rbb 99/10/12 10:54:33
Modified: src/lib/apr/lib apr_pools.c
Log:
Fix a bug in pool locking. The current logic requires recursive mutex's,
which are non-portable. This fix ensures that when clearing and destroying
pools, we only try to grab the mutex once. The fact that APR locks are
not recursive will be documented in a later commit.
Revision Changes Path
1.18 +15 -5 apache-2.0/src/lib/apr/lib/apr_pools.c
Index: apr_pools.c
===================================================================
RCS file: /home/cvs/apache-2.0/src/lib/apr/lib/apr_pools.c,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- apr_pools.c 1999/10/11 22:39:36 1.17
+++ apr_pools.c 1999/10/12 17:54:32 1.18
@@ -557,15 +557,25 @@
void ap_destroy_real_pool(ap_pool_t *);
-static void ap_clear_real_pool(ap_pool_t *a)
+/* We only want to lock the mutex if we are being called from ap_clear_pool.
+ * This is because if we also call this function from ap_destroy_real_pool,
+ * which also locks the same mutex, and recursive locks aren't portable.
+ * This way, we are garaunteed that we only lock this mutex once when calling
+ * either one of these functions.
+ */
+static void ap_clear_real_pool(ap_pool_t *a, int clearcaller)
{
ap_block_alarms();
- ap_lock(alloc_mutex);
+ if (clearcaller) {
+ ap_lock(alloc_mutex);
+ }
while (a->sub_pools) {
ap_destroy_real_pool(a->sub_pools);
+ }
+ if (clearcaller) {
+ ap_unlock(alloc_mutex);
}
- ap_unlock(alloc_mutex);
/*
* Don't hold the mutex during cleanups.
*/
@@ -598,13 +608,13 @@
API_EXPORT(void) ap_clear_pool(struct context_t *a)
{
- ap_clear_real_pool(a->pool);
+ ap_clear_real_pool(a->pool, 1);
}
API_EXPORT(void) ap_destroy_real_pool(ap_pool_t *a)
{
ap_block_alarms();
- ap_clear_real_pool(a);
+ ap_clear_real_pool(a, 0);
ap_lock(alloc_mutex);
if (a->parent) {