apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s.@apache.org
Subject svn commit: r1460182 - in /apr/apr/trunk: include/apr_pools.h memory/unix/apr_pools.c threadproc/beos/thread.c threadproc/netware/thread.c threadproc/os2/thread.c threadproc/unix/thread.c threadproc/win32/thread.c
Date Sat, 23 Mar 2013 16:12:00 GMT
Author: sf
Date: Sat Mar 23 16:12:00 2013
New Revision: 1460182

URL: http://svn.apache.org/r1460182
Log:
Add apr_pool_owner_set function to allow use of pool debugging with threads

Actually this function has been mentioned in the docs for over 10 years
but has never been implemented.

Also consistently destroy the thread's pool when it exits normally, not only
on apr_thread_exit(). This was already done on OS2.

Other platforms than unix are untested.


Modified:
    apr/apr/trunk/include/apr_pools.h
    apr/apr/trunk/memory/unix/apr_pools.c
    apr/apr/trunk/threadproc/beos/thread.c
    apr/apr/trunk/threadproc/netware/thread.c
    apr/apr/trunk/threadproc/os2/thread.c
    apr/apr/trunk/threadproc/unix/thread.c
    apr/apr/trunk/threadproc/win32/thread.c

Modified: apr/apr/trunk/include/apr_pools.h
URL: http://svn.apache.org/viewvc/apr/apr/trunk/include/apr_pools.h?rev=1460182&r1=1460181&r2=1460182&view=diff
==============================================================================
--- apr/apr/trunk/include/apr_pools.h (original)
+++ apr/apr/trunk/include/apr_pools.h Sat Mar 23 16:12:00 2013
@@ -741,6 +741,17 @@ APR_DECLARE(void) apr_pool_join(apr_pool
                   __attribute__((nonnull(2)));
 
 /**
+ * Guarantee that a pool is only used by the current thread.
+ * This should be used when a pool is created by a different thread than
+ * the thread it is using, or if there is some locking in use to ensure
+ * that only one thread uses the pool at the same time.
+ *
+ * @param pool The pool
+ * @param flags Flags, currently unused
+ */
+APR_DECLARE(void) apr_pool_owner_set(apr_pool_t *pool, apr_uint32_t flags);
+
+/**
  * Find a pool from something allocated in it.
  * @param mem The thing allocated in the pool
  * @return The pool it is allocated in
@@ -772,6 +783,11 @@ APR_DECLARE(void) apr_pool_lock(apr_pool
 #endif
 #define apr_pool_join(a,b)
 
+#ifdef apr_pool_owner_set
+#undef apr_pool_owner_set
+#endif
+#define apr_pool_owner_set(a,b)
+
 #ifdef apr_pool_lock
 #undef apr_pool_lock
 #endif

Modified: apr/apr/trunk/memory/unix/apr_pools.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/memory/unix/apr_pools.c?rev=1460182&r1=1460181&r2=1460182&view=diff
==============================================================================
--- apr/apr/trunk/memory/unix/apr_pools.c (original)
+++ apr/apr/trunk/memory/unix/apr_pools.c Sat Mar 23 16:12:00 2013
@@ -1474,6 +1474,12 @@ static void apr_pool_check_integrity(apr
 #endif /* (APR_POOL_DEBUG & APR_POOL_DEBUG_OWNER) */
 }
 
+APR_DECLARE(void) apr_pool_owner_set(apr_pool_t *pool, apr_uint32_t flags)
+{
+#if APR_HAS_THREADS && (APR_POOL_DEBUG & APR_POOL_DEBUG_OWNER)
+    pool->owner = apr_os_thread_current();
+#endif
+}
 
 /*
  * Initialization (debug)

Modified: apr/apr/trunk/threadproc/beos/thread.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/threadproc/beos/thread.c?rev=1460182&r1=1460181&r2=1460182&view=diff
==============================================================================
--- apr/apr/trunk/threadproc/beos/thread.c (original)
+++ apr/apr/trunk/threadproc/beos/thread.c Sat Mar 23 16:12:00 2013
@@ -65,7 +65,12 @@ APR_DECLARE(apr_status_t) apr_threadattr
 static void *dummy_worker(void *opaque)
 {
     apr_thread_t *thd = (apr_thread_t*)opaque;
-    return thd->func(thd, thd->data);
+    void *ret;
+
+    apr_pool_owner_set(thd->pool, 0);
+    ret = thd->func(thd, thd->data);
+    apr_pool_destroy(thd->pool);
+    return ret;
 }
 
 APR_DECLARE(apr_status_t) apr_thread_create(apr_thread_t **new, apr_threadattr_t *attr,

Modified: apr/apr/trunk/threadproc/netware/thread.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/threadproc/netware/thread.c?rev=1460182&r1=1460181&r2=1460182&view=diff
==============================================================================
--- apr/apr/trunk/threadproc/netware/thread.c (original)
+++ apr/apr/trunk/threadproc/netware/thread.c Sat Mar 23 16:12:00 2013
@@ -67,7 +67,12 @@ APR_DECLARE(apr_status_t) apr_threadattr
 static void *dummy_worker(void *opaque)
 {
     apr_thread_t *thd = (apr_thread_t *)opaque;
-    return thd->func(thd, thd->data);
+    void *ret;
+
+    apr_pool_owner_set(thd->pool, 0);
+    ret = thd->func(thd, thd->data);
+    apr_pool_destroy(thd->pool);
+    return ret;
 }
 
 apr_status_t apr_thread_create(apr_thread_t **new,

Modified: apr/apr/trunk/threadproc/os2/thread.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/threadproc/os2/thread.c?rev=1460182&r1=1460181&r2=1460182&view=diff
==============================================================================
--- apr/apr/trunk/threadproc/os2/thread.c (original)
+++ apr/apr/trunk/threadproc/os2/thread.c Sat Mar 23 16:12:00 2013
@@ -69,6 +69,7 @@ APR_DECLARE(apr_status_t) apr_threadattr
 static void apr_thread_begin(void *arg)
 {
   apr_thread_t *thread = (apr_thread_t *)arg;
+  apr_pool_owner_set(thread->pool, 0);
   thread->exitval = thread->func(thread, thread->data);
   apr_pool_destroy(thread->pool);
 }

Modified: apr/apr/trunk/threadproc/unix/thread.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/threadproc/unix/thread.c?rev=1460182&r1=1460181&r2=1460182&view=diff
==============================================================================
--- apr/apr/trunk/threadproc/unix/thread.c (original)
+++ apr/apr/trunk/threadproc/unix/thread.c Sat Mar 23 16:12:00 2013
@@ -139,7 +139,12 @@ APR_DECLARE(apr_status_t) apr_threadattr
 static void *dummy_worker(void *opaque)
 {
     apr_thread_t *thread = (apr_thread_t*)opaque;
-    return thread->func(thread, thread->data);
+    void *ret;
+
+    apr_pool_owner_set(thread->pool, 0);
+    ret = thread->func(thread, thread->data);
+    apr_pool_destroy(thread->pool);
+    return ret;
 }
 
 APR_DECLARE(apr_status_t) apr_thread_create(apr_thread_t **new,

Modified: apr/apr/trunk/threadproc/win32/thread.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/threadproc/win32/thread.c?rev=1460182&r1=1460181&r2=1460182&view=diff
==============================================================================
--- apr/apr/trunk/threadproc/win32/thread.c (original)
+++ apr/apr/trunk/threadproc/win32/thread.c Sat Mar 23 16:12:00 2013
@@ -75,8 +75,13 @@ APR_DECLARE(apr_status_t) apr_threadattr
 static void *dummy_worker(void *opaque)
 {
     apr_thread_t *thd = (apr_thread_t *)opaque;
+    void *ret;
+
     TlsSetValue(tls_apr_thread, thd->td);
-    return thd->func(thd, thd->data);
+    apr_pool_owner_set(thd->pool, 0);
+    ret = thd->func(thd, thd->data);
+    apr_pool_destroy(thd->pool);
+    return ret;
 }
 
 APR_DECLARE(apr_status_t) apr_thread_create(apr_thread_t **new,



Mime
View raw message