diff options
Diffstat (limited to 'threadproc/beos/thread.c')
-rw-r--r-- | threadproc/beos/thread.c | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/threadproc/beos/thread.c b/threadproc/beos/thread.c index c372f135e..61d7fd0d7 100644 --- a/threadproc/beos/thread.c +++ b/threadproc/beos/thread.c @@ -69,7 +69,9 @@ static void *dummy_worker(void *opaque) apr_pool_owner_set(thd->pool, 0); ret = thd->func(thd, thd->data); - apr_pool_destroy(thd->pool); + if (thd->detached) { + apr_pool_destroy(thd->pool); + } return ret; } @@ -80,7 +82,7 @@ APR_DECLARE(apr_status_t) apr_thread_create(apr_thread_t **new, apr_threadattr_t int32 temp; apr_status_t stat; - (*new) = (apr_thread_t *)apr_palloc(pool, sizeof(apr_thread_t)); + (*new) = (apr_thread_t *)apr_pcalloc(pool, sizeof(apr_thread_t)); if ((*new) == NULL) { return APR_ENOMEM; } @@ -88,6 +90,7 @@ APR_DECLARE(apr_status_t) apr_thread_create(apr_thread_t **new, apr_threadattr_t (*new)->data = data; (*new)->func = func; (*new)->exitval = -1; + (*new)->detached = (attr && apr_threadattr_detach_get(attr) == APR_DETACH); /* First we create the new thread...*/ if (attr) @@ -126,14 +129,21 @@ int apr_os_thread_equal(apr_os_thread_t tid1, apr_os_thread_t tid2) APR_DECLARE(void) 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)); } 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; @@ -145,6 +155,7 @@ 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; @@ -153,7 +164,12 @@ 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 (suspend_thread(thd->td) == B_NO_ERROR){ + if (thd->detached) { + return APR_EINVAL; + } + + if (suspend_thread(thd->td) == B_NO_ERROR) { + thd->detached = 1; return APR_SUCCESS; } else { |