summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorylavic <ylavic@13f79535-47bb-0310-9956-ffa450edef68>2022-06-30 13:41:32 +0000
committerylavic <ylavic@13f79535-47bb-0310-9956-ffa450edef68>2022-06-30 13:41:32 +0000
commit1ad79b2db044fd8d2caa3f8965391ee9c65851fb (patch)
tree96ad0aaa1f7cbce68295ce63a481cd9199c38ae0
parentc1e5a44c2ed4af3d442e995449f5167e57a3f4ec (diff)
downloadlibapr-1ad79b2db044fd8d2caa3f8965391ee9c65851fb.tar.gz
Revert r1897210, r1897211 and r1884103.
Per https://lists.apache.org/thread/w0wmkpngyffv8t5r22xvt3romxn41ycw git-svn-id: https://svn.apache.org/repos/asf/apr/apr/branches/1.7.x@1902369 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--include/arch/beos/apr_arch_threadproc.h1
-rw-r--r--include/arch/netware/apr_arch_threadproc.h1
-rw-r--r--include/arch/unix/apr_arch_threadproc.h1
-rw-r--r--include/arch/win32/apr_arch_threadproc.h1
-rw-r--r--threadproc/beos/thread.c74
-rw-r--r--threadproc/netware/thread.c90
-rw-r--r--threadproc/os2/thread.c63
-rw-r--r--threadproc/unix/thread.c67
-rw-r--r--threadproc/win32/thread.c77
9 files changed, 99 insertions, 276 deletions
diff --git a/include/arch/beos/apr_arch_threadproc.h b/include/arch/beos/apr_arch_threadproc.h
index b7db0a300..13de05363 100644
--- a/include/arch/beos/apr_arch_threadproc.h
+++ b/include/arch/beos/apr_arch_threadproc.h
@@ -45,7 +45,6 @@ struct apr_thread_t {
void *data;
apr_thread_start_t func;
apr_status_t exitval;
- int detached;
};
struct apr_threadattr_t {
diff --git a/include/arch/netware/apr_arch_threadproc.h b/include/arch/netware/apr_arch_threadproc.h
index ce217aaba..2fee2c00e 100644
--- a/include/arch/netware/apr_arch_threadproc.h
+++ b/include/arch/netware/apr_arch_threadproc.h
@@ -36,7 +36,6 @@ struct apr_thread_t {
void *data;
apr_thread_start_t func;
apr_status_t exitval;
- int detached;
};
struct apr_threadattr_t {
diff --git a/include/arch/unix/apr_arch_threadproc.h b/include/arch/unix/apr_arch_threadproc.h
index adeb51c8a..7a3b3c092 100644
--- a/include/arch/unix/apr_arch_threadproc.h
+++ b/include/arch/unix/apr_arch_threadproc.h
@@ -59,7 +59,6 @@ struct apr_thread_t {
void *data;
apr_thread_start_t func;
apr_status_t exitval;
- int detached;
};
struct apr_threadattr_t {
diff --git a/include/arch/win32/apr_arch_threadproc.h b/include/arch/win32/apr_arch_threadproc.h
index b39fdbbea..d3ce9c518 100644
--- a/include/arch/win32/apr_arch_threadproc.h
+++ b/include/arch/win32/apr_arch_threadproc.h
@@ -31,7 +31,6 @@ struct apr_thread_t {
void *data;
apr_thread_start_t func;
apr_status_t exitval;
- int exited;
};
struct apr_threadattr_t {
diff --git a/threadproc/beos/thread.c b/threadproc/beos/thread.c
index 269ee9cb6..8d8383942 100644
--- a/threadproc/beos/thread.c
+++ b/threadproc/beos/thread.c
@@ -65,13 +65,7 @@ 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;
-
- ret = thd->func(thd, thd->data);
- if (thd->detached) {
- apr_pool_destroy(thd->pool);
- }
- return ret;
+ return thd->func(thd, thd->data);
}
APR_DECLARE(apr_status_t) apr_thread_create(apr_thread_t **new, apr_threadattr_t *attr,
@@ -80,56 +74,39 @@ APR_DECLARE(apr_status_t) apr_thread_create(apr_thread_t **new, apr_threadattr_t
{
int32 temp;
apr_status_t stat;
- apr_allocator_t *allocator;
- (*new) = (apr_thread_t *)apr_pcalloc(pool, sizeof(apr_thread_t));
+ (*new) = (apr_thread_t *)apr_palloc(pool, sizeof(apr_thread_t));
if ((*new) == NULL) {
return APR_ENOMEM;
}
- /* The thread can be detached anytime (from the creation or later with
- * apr_thread_detach), so it needs its own pool and allocator to not
- * depend on a parent pool which could be destroyed before the thread
- * exits. The allocator needs no mutex obviously since the pool should
- * not be used nor create children pools outside the thread.
- */
- stat = apr_allocator_create(&allocator);
- if (stat != APR_SUCCESS) {
- return stat;
- }
- stat = apr_pool_create_unmanaged_ex(&(*new)->pool,
- apr_pool_abort_get(pool),
- allocator);
- if (stat != APR_SUCCESS) {
- apr_allocator_destroy(allocator);
- return stat;
- }
- apr_allocator_owner_set(allocator, (*new)->pool);
-
(*new)->data = data;
(*new)->func = func;
(*new)->exitval = -1;
- (*new)->detached = (attr && apr_threadattr_detach_get(attr) == APR_DETACH);
-
- if (attr)
- temp = attr->attr;
- else
- temp = B_NORMAL_PRIORITY;
/* First we create the new thread...*/
+ if (attr)
+ temp = attr->attr;
+ else
+ temp = B_NORMAL_PRIORITY;
+
+ stat = apr_pool_create(&(*new)->pool, pool);
+ if (stat != APR_SUCCESS) {
+ return stat;
+ }
+
(*new)->td = spawn_thread((thread_func)dummy_worker,
"apr thread",
temp,
(*new));
/* Now we try to run it...*/
- if (resume_thread((*new)->td) != B_NO_ERROR) {
- stat = errno;
- apr_pool_destroy((*new)->pool);
- return stat;
+ if (resume_thread((*new)->td) == B_NO_ERROR) {
+ return APR_SUCCESS;
}
-
- return APR_SUCCESS;
+ else {
+ return errno;
+ }
}
APR_DECLARE(apr_os_thread_t) apr_os_thread_current(void)
@@ -144,10 +121,8 @@ int apr_os_thread_equal(apr_os_thread_t tid1, apr_os_thread_t tid2)
APR_DECLARE(apr_status_t) apr_thread_exit(apr_thread_t *thd, apr_status_t retval)
{
+ apr_pool_destroy(thd->pool);
thd->exitval = retval;
- if (thd->detached) {
- apr_pool_destroy(thd->pool);
- }
exit_thread ((status_t)(retval));
/* This will never be reached... */
return APR_SUCCESS;
@@ -156,11 +131,6 @@ APR_DECLARE(apr_status_t) apr_thread_exit(apr_thread_t *thd, apr_status_t retval
APR_DECLARE(apr_status_t) apr_thread_join(apr_status_t *retval, apr_thread_t *thd)
{
status_t rv = 0, ret;
-
- if (thd->detached) {
- return APR_EINVAL;
- }
-
ret = wait_for_thread(thd->td, &rv);
if (ret == B_NO_ERROR) {
*retval = rv;
@@ -172,7 +142,6 @@ APR_DECLARE(apr_status_t) apr_thread_join(apr_status_t *retval, apr_thread_t *th
*/
if (thd->exitval != -1) {
*retval = thd->exitval;
- apr_pool_destroy(thd->pool);
return APR_SUCCESS;
} else
return ret;
@@ -181,12 +150,7 @@ APR_DECLARE(apr_status_t) apr_thread_join(apr_status_t *retval, apr_thread_t *th
APR_DECLARE(apr_status_t) apr_thread_detach(apr_thread_t *thd)
{
- if (thd->detached) {
- return APR_EINVAL;
- }
-
- if (suspend_thread(thd->td) == B_NO_ERROR) {
- thd->detached = 1;
+ if (suspend_thread(thd->td) == B_NO_ERROR){
return APR_SUCCESS;
}
else {
diff --git a/threadproc/netware/thread.c b/threadproc/netware/thread.c
index 2f126539b..f98366855 100644
--- a/threadproc/netware/thread.c
+++ b/threadproc/netware/thread.c
@@ -67,13 +67,7 @@ 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;
-
- ret = thd->func(thd, thd->data);
- if (thd->detached) {
- apr_pool_destroy(thd->pool);
- }
- return ret;
+ return thd->func(thd, thd->data);
}
apr_status_t apr_thread_create(apr_thread_t **new,
@@ -84,48 +78,14 @@ apr_status_t apr_thread_create(apr_thread_t **new,
{
apr_status_t stat;
unsigned long flags = NX_THR_BIND_CONTEXT;
+ char threadName[NX_MAX_OBJECT_NAME_LEN+1];
size_t stack_size = APR_DEFAULT_STACK_SIZE;
- apr_allocator_t *allocator;
-
- (*new) = (apr_thread_t *)apr_pcalloc(pool, sizeof(apr_thread_t));
- if ((*new) == NULL) {
- return APR_ENOMEM;
- }
-
- /* The thread can be detached anytime (from the creation or later with
- * apr_thread_detach), so it needs its own pool and allocator to not
- * depend on a parent pool which could be destroyed before the thread
- * exits. The allocator needs no mutex obviously since the pool should
- * not be used nor create children pools outside the thread.
- */
- stat = apr_allocator_create(&allocator);
- if (stat != APR_SUCCESS) {
- return stat;
- }
- stat = apr_pool_create_unmanaged_ex(&(*new)->pool,
- apr_pool_abort_get(pool),
- allocator);
- if (stat != APR_SUCCESS) {
- apr_allocator_destroy(allocator);
- return stat;
- }
- apr_allocator_owner_set(allocator, (*new)->pool);
- (*new)->data = data;
- (*new)->func = func;
- (*new)->exitval = -1;
- (*new)->detached = (attr && apr_threadattr_detach_get(attr) == APR_DETACH);
if (attr && attr->thread_name) {
- (*new)->thread_name = apr_pstrndup(pool, ttr->thread_name,
- NX_MAX_OBJECT_NAME_LEN);
+ strncpy (threadName, attr->thread_name, NX_MAX_OBJECT_NAME_LEN);
}
else {
- (*new)->thread_name = apr_psprintf(pool, "APR_thread %04d",
- ++thread_count);
- }
- if ((*new)->thread_name == NULL) {
- apr_pool_destroy((*new)->pool);
- return APR_ENOMEM;
+ sprintf(threadName, "APR_thread %04ld", ++thread_count);
}
/* An original stack size of 0 will allow NXCreateThread() to
@@ -137,6 +97,21 @@ apr_status_t apr_thread_create(apr_thread_t **new,
stack_size = attr->stack_size;
}
+ (*new) = (apr_thread_t *)apr_palloc(pool, sizeof(apr_thread_t));
+
+ if ((*new) == NULL) {
+ return APR_ENOMEM;
+ }
+
+ (*new)->data = data;
+ (*new)->func = func;
+ (*new)->thread_name = (char*)apr_pstrdup(pool, threadName);
+
+ stat = apr_pool_create(&(*new)->pool, pool);
+ if (stat != APR_SUCCESS) {
+ return stat;
+ }
+
if (attr && attr->detach) {
flags |= NX_THR_DETACHED;
}
@@ -149,21 +124,19 @@ apr_status_t apr_thread_create(apr_thread_t **new,
/* unsigned long flags */ NX_CTX_NORMAL,
/* int *error */ &stat);
- (void) NXContextSetName(
+ stat = NXContextSetName(
/* NXContext_t ctx */ (*new)->ctx,
- /* const char *name */ (*new)->thread_name);
+ /* const char *name */ threadName);
stat = NXThreadCreate(
/* NXContext_t context */ (*new)->ctx,
/* unsigned long flags */ flags,
/* NXThreadId_t *thread_id */ &(*new)->td);
- if (stat) {
- apr_pool_destroy((*new)->pool);
- return stat;
- }
+ if (stat == 0)
+ return APR_SUCCESS;
- return APR_SUCCESS;
+ return(stat); /* if error */
}
apr_os_thread_t apr_os_thread_current()
@@ -185,9 +158,7 @@ apr_status_t apr_thread_exit(apr_thread_t *thd,
apr_status_t retval)
{
thd->exitval = retval;
- if (thd->detached) {
- apr_pool_destroy(thd->pool);
- }
+ apr_pool_destroy(thd->pool);
NXThreadExit(NULL);
return APR_SUCCESS;
}
@@ -198,13 +169,8 @@ apr_status_t apr_thread_join(apr_status_t *retval,
apr_status_t stat;
NXThreadId_t dthr;
- if (thd->detached) {
- return APR_EINVAL;
- }
-
if ((stat = NXThreadJoin(thd->td, &dthr, NULL)) == 0) {
*retval = thd->exitval;
- apr_pool_destroy(thd->pool);
return APR_SUCCESS;
}
else {
@@ -214,12 +180,6 @@ apr_status_t apr_thread_join(apr_status_t *retval,
apr_status_t apr_thread_detach(apr_thread_t *thd)
{
- if (thd->detached) {
- return APR_EINVAL;
- }
-
- thd->detached = 1;
-
return APR_SUCCESS;
}
diff --git a/threadproc/os2/thread.c b/threadproc/os2/thread.c
index 43bc4a1b0..00ec4eb5c 100644
--- a/threadproc/os2/thread.c
+++ b/threadproc/os2/thread.c
@@ -24,8 +24,6 @@
#include "apr_arch_file_io.h"
#include <stdlib.h>
-
-
APR_DECLARE(apr_status_t) apr_threadattr_create(apr_threadattr_t **new, apr_pool_t *pool)
{
(*new) = (apr_threadattr_t *)apr_palloc(pool, sizeof(apr_threadattr_t));
@@ -68,13 +66,10 @@ APR_DECLARE(apr_status_t) apr_threadattr_guardsize_set(apr_threadattr_t *attr,
return APR_ENOTIMPL;
}
-static void dummy_worker(void *opaque)
+static void apr_thread_begin(void *arg)
{
- apr_thread_t *thread = (apr_thread_t *)opaque;
+ apr_thread_t *thread = (apr_thread_t *)arg;
thread->exitval = thread->func(thread, thread->data);
- if (thd->attr->attr & APR_THREADATTR_DETACHED) {
- apr_pool_destroy(thread->pool);
- }
}
@@ -85,51 +80,38 @@ APR_DECLARE(apr_status_t) apr_thread_create(apr_thread_t **new, apr_threadattr_t
{
apr_status_t stat;
apr_thread_t *thread;
- apr_allocator_t *allocator;
-
- *new = thread = (apr_thread_t *)apr_pcalloc(pool, sizeof(apr_thread_t));
+
+ thread = (apr_thread_t *)apr_palloc(pool, sizeof(apr_thread_t));
+ *new = thread;
+
if (thread == NULL) {
return APR_ENOMEM;
}
- /* The thread can be detached anytime (from the creation or later with
- * apr_thread_detach), so it needs its own pool and allocator to not
- * depend on a parent pool which could be destroyed before the thread
- * exits. The allocator needs no mutex obviously since the pool should
- * not be used nor create children pools outside the thread.
- */
- stat = apr_allocator_create(&allocator);
- if (stat != APR_SUCCESS) {
- return stat;
- }
- stat = apr_pool_create_unmanaged_ex(&thread->pool,
- apr_pool_abort_get(pool),
- allocator);
+ thread->attr = attr;
+ thread->func = func;
+ thread->data = data;
+ stat = apr_pool_create(&thread->pool, pool);
+
if (stat != APR_SUCCESS) {
- apr_allocator_destroy(allocator);
return stat;
}
- apr_allocator_owner_set(allocator, thread->pool);
- thread->func = func;
- thread->data = data;
if (attr == NULL) {
- stat = apr_threadattr_create(&attr, thread->pool);
+ stat = apr_threadattr_create(&thread->attr, thread->pool);
+
if (stat != APR_SUCCESS) {
- apr_pool_destroy(thread->pool);
return stat;
}
}
- thread->attr = attr;
- thread->tid = _beginthread(dummy_worker, NULL,
+ thread->tid = _beginthread(apr_thread_begin, NULL,
thread->attr->stacksize > 0 ?
thread->attr->stacksize : APR_THREAD_STACKSIZE,
thread);
+
if (thread->tid < 0) {
- stat = errno;
- apr_pool_destroy(thread->pool);
- return stat;
+ return errno;
}
return APR_SUCCESS;
@@ -150,9 +132,6 @@ APR_DECLARE(apr_os_thread_t) apr_os_thread_current()
APR_DECLARE(apr_status_t) apr_thread_exit(apr_thread_t *thd, apr_status_t retval)
{
thd->exitval = retval;
- if (thd->attr->attr & APR_THREADATTR_DETACHED) {
- apr_pool_destroy(thd->pool);
- }
_endthread();
return -1; /* If we get here something's wrong */
}
@@ -173,22 +152,14 @@ APR_DECLARE(apr_status_t) apr_thread_join(apr_status_t *retval, apr_thread_t *th
rc = 0; /* Thread had already terminated */
*retval = thd->exitval;
- if (rc == 0) {
- apr_pool_destroy(thd->pool);
- }
- return APR_FROM_OS_ERROR(rc);
+ return APR_OS2_STATUS(rc);
}
APR_DECLARE(apr_status_t) apr_thread_detach(apr_thread_t *thd)
{
- if (thd->attr->attr & APR_THREADATTR_DETACHED) {
- return APR_EINVAL;
- }
-
thd->attr->attr |= APR_THREADATTR_DETACHED;
-
return APR_SUCCESS;
}
diff --git a/threadproc/unix/thread.c b/threadproc/unix/thread.c
index e5919a4b8..6d060be55 100644
--- a/threadproc/unix/thread.c
+++ b/threadproc/unix/thread.c
@@ -139,13 +139,7 @@ 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;
- void *ret;
-
- ret = thread->func(thread, thread->data);
- if (thread->detached) {
- apr_pool_destroy(thread->pool);
- }
- return ret;
+ return thread->func(thread, thread->data);
}
APR_DECLARE(apr_status_t) apr_thread_create(apr_thread_t **new,
@@ -156,55 +150,42 @@ APR_DECLARE(apr_status_t) apr_thread_create(apr_thread_t **new,
{
apr_status_t stat;
pthread_attr_t *temp;
- apr_allocator_t *allocator;
-
+
(*new) = (apr_thread_t *)apr_pcalloc(pool, sizeof(apr_thread_t));
+
if ((*new) == NULL) {
return APR_ENOMEM;
}
- /* The thread can be detached anytime (from the creation or later with
- * apr_thread_detach), so it needs its own pool and allocator to not
- * depend on a parent pool which could be destroyed before the thread
- * exits. The allocator needs no mutex obviously since the pool should
- * not be used nor create children pools outside the thread.
- */
- stat = apr_allocator_create(&allocator);
- if (stat != APR_SUCCESS) {
- return stat;
- }
- stat = apr_pool_create_unmanaged_ex(&(*new)->pool,
- apr_pool_abort_get(pool),
- allocator);
- if (stat != APR_SUCCESS) {
- apr_allocator_destroy(allocator);
- return stat;
- }
- apr_allocator_owner_set(allocator, (*new)->pool);
-
- (*new)->data = data;
- (*new)->func = func;
- (*new)->detached = (attr && apr_threadattr_detach_get(attr) == APR_DETACH);
(*new)->td = (pthread_t *)apr_pcalloc(pool, sizeof(pthread_t));
+
if ((*new)->td == NULL) {
- apr_pool_destroy((*new)->pool);
return APR_ENOMEM;
}
+ (*new)->data = data;
+ (*new)->func = func;
+
if (attr)
temp = &attr->attr;
else
temp = NULL;
- if ((stat = pthread_create((*new)->td, temp, dummy_worker, (*new)))) {
+ stat = apr_pool_create(&(*new)->pool, pool);
+ if (stat != APR_SUCCESS) {
+ return stat;
+ }
+
+ if ((stat = pthread_create((*new)->td, temp, dummy_worker, (*new))) == 0) {
+ return APR_SUCCESS;
+ }
+ else {
#ifdef HAVE_ZOS_PTHREADS
stat = errno;
#endif
- apr_pool_destroy((*new)->pool);
+
return stat;
}
-
- return APR_SUCCESS;
}
APR_DECLARE(apr_os_thread_t) apr_os_thread_current(void)
@@ -222,9 +203,7 @@ APR_DECLARE(apr_status_t) apr_thread_exit(apr_thread_t *thd,
apr_status_t retval)
{
thd->exitval = retval;
- if (thd->detached) {
- apr_pool_destroy(thd->pool);
- }
+ apr_pool_destroy(thd->pool);
pthread_exit(NULL);
return APR_SUCCESS;
}
@@ -235,13 +214,8 @@ APR_DECLARE(apr_status_t) apr_thread_join(apr_status_t *retval,
apr_status_t stat;
apr_status_t *thread_stat;
- if (thd->detached) {
- return APR_EINVAL;
- }
-
if ((stat = pthread_join(*thd->td,(void *)&thread_stat)) == 0) {
*retval = thd->exitval;
- apr_pool_destroy(thd->pool);
return APR_SUCCESS;
}
else {
@@ -257,16 +231,11 @@ APR_DECLARE(apr_status_t) apr_thread_detach(apr_thread_t *thd)
{
apr_status_t stat;
- if (thd->detached) {
- return APR_EINVAL;
- }
-
#ifdef HAVE_ZOS_PTHREADS
if ((stat = pthread_detach(thd->td)) == 0) {
#else
if ((stat = pthread_detach(*thd->td)) == 0) {
#endif
- thd->detached = 1;
return APR_SUCCESS;
}
diff --git a/threadproc/win32/thread.c b/threadproc/win32/thread.c
index 6b04abb98..25034571e 100644
--- a/threadproc/win32/thread.c
+++ b/threadproc/win32/thread.c
@@ -75,14 +75,8 @@ 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);
- ret = thd->func(thd, thd->data);
- if (!thd->td) { /* detached? */
- apr_pool_destroy(thd->pool);
- }
- return ret;
+ return thd->func(thd, thd->data);
}
APR_DECLARE(apr_status_t) apr_thread_create(apr_thread_t **new,
@@ -91,36 +85,22 @@ APR_DECLARE(apr_status_t) apr_thread_create(apr_thread_t **new,
void *data, apr_pool_t *pool)
{
apr_status_t stat;
- unsigned temp;
+ unsigned temp;
HANDLE handle;
- apr_allocator_t *allocator;
-
- (*new) = (apr_thread_t *)apr_pcalloc(pool, sizeof(apr_thread_t));
+
+ (*new) = (apr_thread_t *)apr_palloc(pool, sizeof(apr_thread_t));
+
if ((*new) == NULL) {
return APR_ENOMEM;
}
- /* The thread can be detached anytime (from the creation or later with
- * apr_thread_detach), so it needs its own pool and allocator to not
- * depend on a parent pool which could be destroyed before the thread
- * exits. The allocator needs no mutex obviously since the pool should
- * not be used nor create children pools outside the thread.
- */
- stat = apr_allocator_create(&allocator);
- if (stat != APR_SUCCESS) {
- return stat;
- }
- stat = apr_pool_create_unmanaged_ex(&(*new)->pool,
- apr_pool_abort_get(pool),
- allocator);
+ (*new)->data = data;
+ (*new)->func = func;
+ (*new)->td = NULL;
+ stat = apr_pool_create(&(*new)->pool, pool);
if (stat != APR_SUCCESS) {
- apr_allocator_destroy(allocator);
return stat;
}
- apr_allocator_owner_set(allocator, (*new)->pool);
-
- (*new)->data = data;
- (*new)->func = func;
/* Use 0 for default Thread Stack Size, because that will
* default the stack to the same size as the calling thread.
@@ -130,26 +110,21 @@ APR_DECLARE(apr_status_t) apr_thread_create(apr_thread_t **new,
(DWORD) (attr ? attr->stacksize : 0),
(unsigned int (APR_THREAD_FUNC *)(void *))dummy_worker,
(*new), 0, &temp)) == 0) {
- stat = APR_FROM_OS_ERROR(_doserrno);
- apr_pool_destroy((*new)->pool);
- return stat;
+ return APR_FROM_OS_ERROR(_doserrno);
}
#else
if ((handle = CreateThread(NULL,
attr && attr->stacksize > 0 ? attr->stacksize : 0,
(unsigned int (APR_THREAD_FUNC *)(void *))dummy_worker,
(*new), 0, &temp)) == 0) {
- stat = apr_get_os_error();
- apr_pool_destroy((*new)->pool);
- return stat;
+ return apr_get_os_error();
}
#endif
if (attr && attr->detach) {
CloseHandle(handle);
}
- else {
+ else
(*new)->td = handle;
- }
return APR_SUCCESS;
}
@@ -157,11 +132,9 @@ APR_DECLARE(apr_status_t) apr_thread_create(apr_thread_t **new,
APR_DECLARE(apr_status_t) apr_thread_exit(apr_thread_t *thd,
apr_status_t retval)
{
- thd->exited = 1;
thd->exitval = retval;
- if (!thd->td) { /* detached? */
- apr_pool_destroy(thd->pool);
- }
+ apr_pool_destroy(thd->pool);
+ thd->pool = NULL;
#ifndef _WIN32_WCE
_endthreadex(0);
#else
@@ -174,40 +147,30 @@ APR_DECLARE(apr_status_t) apr_thread_join(apr_status_t *retval,
apr_thread_t *thd)
{
apr_status_t rv = APR_SUCCESS;
- DWORD ret;
if (!thd->td) {
/* Can not join on detached threads */
return APR_DETACH;
}
-
- ret = WaitForSingleObject(thd->td, INFINITE);
- if (ret == WAIT_OBJECT_0 || ret == WAIT_ABANDONED) {
+ rv = WaitForSingleObject(thd->td, INFINITE);
+ if ( rv == WAIT_OBJECT_0 || rv == WAIT_ABANDONED) {
/* If the thread_exit has been called */
- if (thd->exited)
+ if (!thd->pool)
*retval = thd->exitval;
else
rv = APR_INCOMPLETE;
}
else
rv = apr_get_os_error();
-
- if (rv == APR_SUCCESS) {
- CloseHandle(thd->td);
- apr_pool_destroy(thd->pool);
- thd->td = NULL;
- }
+ CloseHandle(thd->td);
+ thd->td = NULL;
return rv;
}
APR_DECLARE(apr_status_t) apr_thread_detach(apr_thread_t *thd)
{
- if (!thd->td) {
- return APR_EINVAL;
- }
-
- if (CloseHandle(thd->td)) {
+ if (thd->td && CloseHandle(thd->td)) {
thd->td = NULL;
return APR_SUCCESS;
}