summaryrefslogtreecommitdiff
path: root/threadproc/beos/thread.c
diff options
context:
space:
mode:
Diffstat (limited to 'threadproc/beos/thread.c')
-rw-r--r--threadproc/beos/thread.c74
1 files changed, 19 insertions, 55 deletions
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 {