You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@apr.apache.org by mt...@apache.org on 2008/04/12 09:22:43 UTC
svn commit: r647390 - in /apr/apr/trunk: CHANGES include/apr_pools.h
memory/unix/apr_pools.c
Author: mturk
Date: Sat Apr 12 00:22:14 2008
New Revision: 647390
URL: http://svn.apache.org/viewvc?rev=647390&view=rev
Log:
Introduce apr_pool_pre_cleanup_register
Modified:
apr/apr/trunk/CHANGES
apr/apr/trunk/include/apr_pools.h
apr/apr/trunk/memory/unix/apr_pools.c
Modified: apr/apr/trunk/CHANGES
URL: http://svn.apache.org/viewvc/apr/apr/trunk/CHANGES?rev=647390&r1=647389&r2=647390&view=diff
==============================================================================
--- apr/apr/trunk/CHANGES [utf-8] (original)
+++ apr/apr/trunk/CHANGES [utf-8] Sat Apr 12 00:22:14 2008
@@ -1,6 +1,13 @@
-*- coding: utf-8 -*-
Changes for APR 1.3.0
+ *) Introduce apr_pool_pre_cleanup_register() for registering
+ a cleanup that is called before any subpool is destroyed
+ within apr_pool_clear or apr_pool_destroy.
+ This allows to register a cleanup that will notify subpools
+ about its inevitable destruction.
+ [Mladen Turk]
+
*) Introduce apr_pool_create_core_ex() for creation of standalone
pools without parent. This function should be used for short
living pools, usually ones that are created and destroyed
Modified: apr/apr/trunk/include/apr_pools.h
URL: http://svn.apache.org/viewvc/apr/apr/trunk/include/apr_pools.h?rev=647390&r1=647389&r2=647390&view=diff
==============================================================================
--- apr/apr/trunk/include/apr_pools.h (original)
+++ apr/apr/trunk/include/apr_pools.h Sat Apr 12 00:22:14 2008
@@ -560,6 +560,23 @@
apr_status_t (*child_cleanup)(void *));
/**
+ * Register a function to be called when a pool is cleared or destroyed.
+ *
+ * Unlike apr_pool_cleanup_register which register a cleanup
+ * that is called AFTER all subpools are destroyed this function register
+ * a function that will be called before any of the subpool is destoryed.
+ *
+ * @param p The pool register the cleanup with
+ * @param data The data to pass to the cleanup function.
+ * @param plain_cleanup The function to call when the pool is cleared
+ * or destroyed
+ */
+APR_DECLARE(void) apr_pool_pre_cleanup_register(
+ apr_pool_t *p,
+ const void *data,
+ apr_status_t (*plain_cleanup)(void *));
+
+/**
* Remove a previously registered cleanup function.
*
* The cleanup most recently registered with @a p having the same values of
Modified: apr/apr/trunk/memory/unix/apr_pools.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/memory/unix/apr_pools.c?rev=647390&r1=647389&r2=647390&view=diff
==============================================================================
--- apr/apr/trunk/memory/unix/apr_pools.c (original)
+++ apr/apr/trunk/memory/unix/apr_pools.c Sat Apr 12 00:22:14 2008
@@ -501,6 +501,8 @@
#ifdef NETWARE
apr_os_proc_t owner_proc;
#endif /* defined(NETWARE) */
+ cleanup_t *pre_cleanups;
+ cleanup_t *free_pre_cleanups;
};
#define SIZEOF_POOL_T APR_ALIGN_DEFAULT(sizeof(apr_pool_t))
@@ -714,6 +716,11 @@
{
apr_memnode_t *active;
+ /* Run pre destroy cleanups */
+ run_cleanups(&pool->pre_cleanups);
+ pool->pre_cleanups = NULL;
+ pool->free_pre_cleanups = NULL;
+
/* Destroy the subpools. The subpools will detach themselves from
* this pool thus this loop is safe and easy.
*/
@@ -752,6 +759,11 @@
apr_memnode_t *active;
apr_allocator_t *allocator;
+ /* Run pre destroy cleanups */
+ run_cleanups(&pool->pre_cleanups);
+ pool->pre_cleanups = NULL;
+ pool->free_pre_cleanups = NULL;
+
/* Destroy the subpools. The subpools will detach themselve from
* this pool thus this loop is safe and easy.
*/
@@ -856,6 +868,8 @@
pool->child = NULL;
pool->cleanups = NULL;
pool->free_cleanups = NULL;
+ pool->pre_cleanups = NULL;
+ pool->free_pre_cleanups = NULL;
pool->subprocesses = NULL;
pool->user_data = NULL;
pool->tag = NULL;
@@ -935,6 +949,8 @@
pool->child = NULL;
pool->cleanups = NULL;
pool->free_cleanups = NULL;
+ pool->pre_cleanups = NULL;
+ pool->free_pre_cleanups = NULL;
pool->subprocesses = NULL;
pool->user_data = NULL;
pool->tag = NULL;
@@ -1467,6 +1483,11 @@
debug_node_t *node;
apr_uint32_t index;
+ /* Run pre destroy cleanups */
+ run_cleanups(&pool->pre_cleanups);
+ pool->pre_cleanups = NULL;
+ pool->free_pre_cleanups = NULL;
+
/* Destroy the subpools. The subpools will detach themselves from
* this pool thus this loop is safe and easy.
*/
@@ -2175,6 +2196,32 @@
lastp = &c->next;
c = c->next;
}
+
+ /* Remove any pre-cleanup as well */
+ c = p->pre_cleanups;
+ lastp = &p->pre_cleanups;
+ while (c) {
+#if APR_POOL_DEBUG
+ /* Some cheap loop detection to catch a corrupt list: */
+ if (c == c->next
+ || (c->next && c == c->next->next)
+ || (c->next && c->next->next && c == c->next->next->next)) {
+ abort();
+ }
+#endif
+
+ if (c->data == data && c->plain_cleanup_fn == cleanup_fn) {
+ *lastp = c->next;
+ /* move to freelist */
+ c->next = p->free_pre_cleanups;
+ p->free_pre_cleanups = c;
+ break;
+ }
+
+ lastp = &c->next;
+ c = c->next;
+ }
+
}
APR_DECLARE(void) apr_pool_child_cleanup_set(apr_pool_t *p, const void *data,
Re: svn commit: r647390 - in /apr/apr/trunk: CHANGES include/apr_pools.h
memory/unix/apr_pools.c
Posted by Ruediger Pluem <rp...@apache.org>.
On 04/12/2008 09:22 AM, mturk@apache.org wrote:
> Author: mturk
> Date: Sat Apr 12 00:22:14 2008
> New Revision: 647390
>
> URL: http://svn.apache.org/viewvc?rev=647390&view=rev
> Log:
> Introduce apr_pool_pre_cleanup_register
>
> Modified:
> apr/apr/trunk/CHANGES
> apr/apr/trunk/include/apr_pools.h
> apr/apr/trunk/memory/unix/apr_pools.c
>
Where is the implementation of apr_pool_pre_cleanup_register?
Regards
RĂ¼diger