summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Fritsch <sf@apache.org>2013-03-23 16:12:00 +0000
committerStefan Fritsch <sf@apache.org>2013-03-23 16:12:00 +0000
commit5c100ea811811cc92bd8fbcaedcbcf58e3c7599c (patch)
treed7528c0c5b50c11450b4d7f9d57aa60043fa7365
parentfdbb812969d7f7cfe055c1fbec8e5d40a35eaf40 (diff)
downloadapr-5c100ea811811cc92bd8fbcaedcbcf58e3c7599c.tar.gz
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. git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@1460182 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--include/apr_pools.h16
-rw-r--r--memory/unix/apr_pools.c6
-rw-r--r--threadproc/beos/thread.c7
-rw-r--r--threadproc/netware/thread.c7
-rw-r--r--threadproc/os2/thread.c1
-rw-r--r--threadproc/unix/thread.c7
-rw-r--r--threadproc/win32/thread.c7
7 files changed, 47 insertions, 4 deletions
diff --git a/include/apr_pools.h b/include/apr_pools.h
index 755320e5c..6f50ade8f 100644
--- a/include/apr_pools.h
+++ b/include/apr_pools.h
@@ -741,6 +741,17 @@ APR_DECLARE(void) apr_pool_join(apr_pool_t *p, apr_pool_t *sub)
__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_t *pool, int flag);
#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
diff --git a/memory/unix/apr_pools.c b/memory/unix/apr_pools.c
index 5fe0701c7..b39e0cf87 100644
--- a/memory/unix/apr_pools.c
+++ b/memory/unix/apr_pools.c
@@ -1474,6 +1474,12 @@ static void apr_pool_check_integrity(apr_pool_t *pool)
#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)
diff --git a/threadproc/beos/thread.c b/threadproc/beos/thread.c
index 8d8383942..01bc7a973 100644
--- a/threadproc/beos/thread.c
+++ b/threadproc/beos/thread.c
@@ -65,7 +65,12 @@ APR_DECLARE(apr_status_t) apr_threadattr_guardsize_set(apr_threadattr_t *attr,
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,
diff --git a/threadproc/netware/thread.c b/threadproc/netware/thread.c
index 82b846aaf..5e3d99d55 100644
--- a/threadproc/netware/thread.c
+++ b/threadproc/netware/thread.c
@@ -67,7 +67,12 @@ APR_DECLARE(apr_status_t) apr_threadattr_guardsize_set(apr_threadattr_t *attr,
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,
diff --git a/threadproc/os2/thread.c b/threadproc/os2/thread.c
index e2cf3f6a8..9911034ae 100644
--- a/threadproc/os2/thread.c
+++ b/threadproc/os2/thread.c
@@ -69,6 +69,7 @@ APR_DECLARE(apr_status_t) apr_threadattr_guardsize_set(apr_threadattr_t *attr,
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);
}
diff --git a/threadproc/unix/thread.c b/threadproc/unix/thread.c
index 5639ac706..6fc949f83 100644
--- a/threadproc/unix/thread.c
+++ b/threadproc/unix/thread.c
@@ -139,7 +139,12 @@ APR_DECLARE(apr_status_t) apr_threadattr_guardsize_set(apr_threadattr_t *attr,
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,
diff --git a/threadproc/win32/thread.c b/threadproc/win32/thread.c
index 9b9473ad5..c713e1444 100644
--- a/threadproc/win32/thread.c
+++ b/threadproc/win32/thread.c
@@ -75,8 +75,13 @@ APR_DECLARE(apr_status_t) apr_threadattr_guardsize_set(apr_threadattr_t *attr,
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,