Bojan Smojver
Mon, 21 Jul 2008 16:06:31 -0700
On Mon, 2008-07-21 at 22:05 +1000, Bojan Smojver wrote: > For example... After thinking about it a bit more, it appears that we really should not need to fiddle with locking here. Essentially, when we call this, we can assume that root pool and below will not be modified by another thread (because we can always control what root pool is), so we can just go ahead and search in peace. Comments? -- Bojan
Index: memory/unix/apr_pools.c
===================================================================
--- memory/unix/apr_pools.c (revision 678399)
+++ memory/unix/apr_pools.c (working copy)
@@ -825,6 +825,33 @@
}
}
+static apr_status_t destroy_safe(apr_pool_t *root, apr_pool_t *pool)
+{
+ apr_pool_t *p;
+
+ for (p = root; p; p = p->sibling) {
+ if (p == pool) {
+ apr_pool_destroy(p);
+ return APR_SUCCESS;
+ }
+ else {
+ if(destroy_safe(p->child, pool) == APR_SUCCESS) {
+ return APR_SUCCESS;
+ }
+ }
+ }
+
+ return APR_EGENERAL;
+}
+
+APR_DECLARE(void) apr_pool_destroy_safe(apr_pool_t *pool,apr_pool_t *root)
+{
+ if (root == NULL)
+ root = global_pool;
+
+ destroy_safe(root->child, pool);
+}
+
APR_DECLARE(apr_status_t) apr_pool_create_ex(apr_pool_t **newpool,
apr_pool_t *parent,
apr_abortfunc_t abort_fn,
Index: include/apr_pools.h
===================================================================
--- include/apr_pools.h (revision 678399)
+++ include/apr_pools.h (working copy)
@@ -371,6 +371,18 @@
APR_DECLARE(void) apr_pool_destroy(apr_pool_t *p);
/**
+ * Destroy the pool only if it can be found as a descendant of the root pool.
+ * This function is used when the pool about to be destroyed may have been
+ * destroyed before.
+ * @param p The pool to destroy
+ * @param r The root pool to start search from, NULL for global pool
+ * @remark This will actually free the memory by calling apr_pool_destroy().
+ * If there is a possibility of anything below root pool of being removed by
+ * another thread, external locking must be used.
+ */
+APR_DECLARE(void) apr_pool_destroy_safe(apr_pool_t *p, apr_pool_t *r);
+
+/**
* Debug version of apr_pool_destroy.
* @param p See: apr_pool_destroy.
* @param file_line Where the function is called from.