Index: srclib/apr/include/apr_thread_proc.h =================================================================== RCS file: /home/cvspublic/apr/include/apr_thread_proc.h,v retrieving revision 1.65 diff -u -r1.65 apr_thread_proc.h --- srclib/apr/include/apr_thread_proc.h 2001/06/06 18:11:06 1.65 +++ srclib/apr/include/apr_thread_proc.h 2001/07/20 00:17:48 @@ -125,7 +125,13 @@ typedef struct apr_other_child_rec_t apr_other_child_rec_t; #endif /* APR_HAS_OTHER_CHILD */ -typedef void *(APR_THREAD_FUNC *apr_thread_start_t)(void *); +struct apr_thread_param_t { + apr_thread_t *t; + void *data; +}; +typedef struct apr_thread_param_t apr_thread_param_t; + +typedef void *(APR_THREAD_FUNC *apr_thread_start_t)(apr_thread_param_t *); enum kill_conditions { kill_never, /* process is never sent any signals */ Index: srclib/apr/test/testthread.c =================================================================== RCS file: /home/cvspublic/apr/test/testthread.c,v retrieving revision 1.17 diff -u -r1.17 testthread.c --- srclib/apr/test/testthread.c 2001/03/14 15:56:44 1.17 +++ srclib/apr/test/testthread.c 2001/07/20 00:17:48 @@ -72,57 +72,66 @@ } #else /* !APR_HAS_THREADS */ -void * APR_THREAD_FUNC thread_func1(void *data); -void * APR_THREAD_FUNC thread_func2(void *data); -void * APR_THREAD_FUNC thread_func3(void *data); -void * APR_THREAD_FUNC thread_func4(void *data); +void * APR_THREAD_FUNC thread_func1(apr_thread_param_t *thrparm); +void * APR_THREAD_FUNC thread_func2(apr_thread_param_t *thrparm); +void * APR_THREAD_FUNC thread_func3(apr_thread_param_t *thrparm); +void * APR_THREAD_FUNC thread_func4(apr_thread_param_t *thrparm); apr_lock_t *thread_lock; apr_pool_t *context; int x = 0; +apr_status_t exit_ret_val = 123; /* just some made up number to check on later */ -void * APR_THREAD_FUNC thread_func1(void *data) +void * APR_THREAD_FUNC thread_func1(apr_thread_param_t *thrparm) { int i; + apr_thread_t *thread = thrparm->t; for (i = 0; i < 10000; i++) { apr_lock_acquire(thread_lock); x++; apr_lock_release(thread_lock); } + apr_thread_exit(thread, &exit_ret_val); return NULL; } -void * APR_THREAD_FUNC thread_func2(void *data) +void * APR_THREAD_FUNC thread_func2(apr_thread_param_t *thrparm) { int i; + apr_thread_t *thread = thrparm->t; for (i = 0; i < 10000; i++) { apr_lock_acquire(thread_lock); x++; apr_lock_release(thread_lock); } + apr_thread_exit(thread, &exit_ret_val); return NULL; } -void * APR_THREAD_FUNC thread_func3(void *data) +void * APR_THREAD_FUNC thread_func3(apr_thread_param_t *thrparm) { int i; + apr_thread_t *thread = thrparm->t; for (i = 0; i < 10000; i++) { apr_lock_acquire(thread_lock); x++; apr_lock_release(thread_lock); } + apr_thread_exit(thread, &exit_ret_val); return NULL; } -void * APR_THREAD_FUNC thread_func4(void *data) +void * APR_THREAD_FUNC thread_func4(apr_thread_param_t *thrparm) { int i; + apr_thread_t *thread = thrparm->t; for (i = 0; i < 10000; i++) { apr_lock_acquire(thread_lock); x++; apr_lock_release(thread_lock); } + apr_thread_exit(thread, &exit_ret_val); return NULL; } @@ -172,7 +181,15 @@ apr_thread_join(&s2, t2); apr_thread_join(&s3, t3); apr_thread_join(&s4, t4); - fprintf (stdout, "OK\n"); + fprintf (stdout, "OK\n"); + + fprintf(stdout, "Checking thread's returned value......."); + if (s1 != exit_ret_val || s2 != exit_ret_val || + s3 != exit_ret_val || s4 != exit_ret_val) { + fprintf(stderr, "Invalid return value (not expected value)\n"); + exit(-1); + } + fprintf(stdout, "OK\n"); fprintf(stdout, "Checking if locks worked......."); if (x != 40000) { Index: srclib/apr/threadproc/beos/thread.c =================================================================== RCS file: /home/cvspublic/apr/threadproc/beos/thread.c,v retrieving revision 1.22 diff -u -r1.22 thread.c --- srclib/apr/threadproc/beos/thread.c 2001/06/14 18:52:05 1.22 +++ srclib/apr/threadproc/beos/thread.c 2001/07/20 00:17:49 @@ -94,13 +94,17 @@ { int32 temp; apr_status_t stat; + struct thread_info_t *thr_info; + apr_thread_t *thread; + apr_thread_param_t *thrparm; - (*new) = (apr_thread_t *)apr_palloc(cont, sizeof(apr_thread_t)); - if ((*new) == NULL) { + thread = (apr_thread_t *)apr_palloc(cont, sizeof(apr_thread_t)); + (*new) = thread; + if (thread == NULL) { return APR_ENOMEM; } - (*new)->cntxt = cont; + thread->cntxt = cont; /* First we create the new thread...*/ if (attr) @@ -108,14 +112,23 @@ else temp = B_NORMAL_PRIORITY; - stat = apr_pool_create(&(*new)->cntxt, cont); + stat = apr_pool_create(&thread->cntxt, cont); if (stat != APR_SUCCESS) { return stat; } - (*new)->td = spawn_thread((thread_func)func, "apr thread", temp, data); + thread->cntxt = cont; + + thrparm = (apr_thread_param_t *)apr_palloc(cont, sizeof(apr_thread_param_t)); + if (thrparm == NULL) { + return APR_ENOMEM; + } + thrparm->t = thread; + thrparm->data = data; + + thread->td = spawn_thread((thread_func)func, "apr thread", temp, thrparm); /* Now we try to run it...*/ - if (resume_thread((*new)->td) == B_NO_ERROR) { + if (resume_thread(thread->td) == B_NO_ERROR) { return APR_SUCCESS; } else { @@ -142,7 +155,11 @@ apr_status_t apr_thread_join(apr_status_t *retval, apr_thread_t *thd) { - if (wait_for_thread(thd->td,(void *)&retval) == B_NO_ERROR) { + apr_status_t *thrstat = NULL; + + if (wait_for_thread(thd->td,(void *)&thrstat) == B_NO_ERROR) { + if (retval != NULL && thrstat != NULL) + *retval = *thrstat; return APR_SUCCESS; } else { Index: srclib/apr/threadproc/os2/thread.c =================================================================== RCS file: /home/cvspublic/apr/threadproc/os2/thread.c,v retrieving revision 1.22 diff -u -r1.22 thread.c --- srclib/apr/threadproc/os2/thread.c 2001/06/16 01:27:15 1.22 +++ srclib/apr/threadproc/os2/thread.c 2001/07/20 00:17:49 @@ -94,8 +94,18 @@ static void apr_thread_begin(void *arg) { - apr_thread_t *thread = (apr_thread_t *)arg; - thread->rv = thread->func(thread->data); + apr_thread_param_t *thrparm; + apr_thread_t *thread = (apr_thread_t *)arg; + + thrparm = (apr_thread_param_t *)apr_palloc(cont, sizeof(apr_thread_param_t)); + if (thrparm == NULL) { + return APR_ENOMEM; + } + + thrparm->t = thread; + thrparm->data = data; + + thread->rv = thread->func(thrparm); } @@ -132,12 +142,23 @@ } } - if (thread->attr->attr & APR_THREADATTR_DETACHED) + if (thread->attr->attr & APR_THREADATTR_DETACHED) { + apr_thread_param_t *thrparm; + + thrparm = (apr_thread_param_t *)apr_palloc(cont, sizeof(apr_thread_param_t)); + if (thrparm == NULL) { + return APR_ENOMEM; + } + + thrparm->t = thread; + thrparm->data = data; + thread->tid = _beginthread((os2_thread_start_t)func, NULL, - APR_THREAD_STACKSIZE, data); - else + APR_THREAD_STACKSIZE, thrparm); + } else { thread->tid = _beginthread(apr_thread_begin, NULL, APR_THREAD_STACKSIZE, thread); + } if (thread->tid < 0) { return errno; @@ -180,7 +201,8 @@ if (rc == ERROR_INVALID_THREADID) rc = 0; /* Thread had already terminated */ - *retval = (apr_status_t)thd->rv; + if (retval != NULL) + *retval = (apr_status_t)thd->rv; return APR_OS2_STATUS(rc); } Index: srclib/apr/threadproc/unix/thread.c =================================================================== RCS file: /home/cvspublic/apr/threadproc/unix/thread.c,v retrieving revision 1.39 diff -u -r1.39 thread.c --- srclib/apr/threadproc/unix/thread.c 2001/06/14 18:52:09 1.39 +++ srclib/apr/threadproc/unix/thread.c 2001/07/20 00:17:49 @@ -122,32 +122,44 @@ { apr_status_t stat; pthread_attr_t *temp; + struct thread_info_t *thr_info; + apr_thread_t *thread; + apr_thread_param_t *thrparm; - (*new) = (apr_thread_t *)apr_pcalloc(cont, sizeof(apr_thread_t)); + thread = (apr_thread_t *)apr_pcalloc(cont, sizeof(apr_thread_t)); + (*new) = thread; - if ((*new) == NULL) { + if (thread == NULL) { return APR_ENOMEM; } - (*new)->td = (pthread_t *)apr_pcalloc(cont, sizeof(pthread_t)); + thread->td = (pthread_t *)apr_pcalloc(cont, sizeof(pthread_t)); - if ((*new)->td == NULL) { + if (thread->td == NULL) { return APR_ENOMEM; } - (*new)->cntxt = cont; - if (attr) temp = attr->attr; else temp = NULL; - - stat = apr_pool_create(&(*new)->cntxt, cont); + + thread->cntxt = cont; + + stat = apr_pool_create(&thread->cntxt, cont); if (stat != APR_SUCCESS) { return stat; } + + thrparm = (apr_thread_param_t *)apr_pcalloc(cont, sizeof(apr_thread_param_t)); + if (thrparm == NULL) { + return APR_ENOMEM; + } - if ((stat = pthread_create((*new)->td, temp, func, data)) == 0) { + thrparm->t = thread; + thrparm->data = data; + + if ((stat = pthread_create(thread->td, temp, func, thrparm)) == 0) { return APR_SUCCESS; } else { @@ -155,7 +167,7 @@ stat = errno; #endif return stat; - } + } } apr_os_thread_t apr_os_thread_current(void) @@ -178,8 +190,11 @@ apr_status_t apr_thread_join(apr_status_t *retval, apr_thread_t *thd) { apr_status_t stat; + apr_status_t *thrstat = NULL; - if ((stat = pthread_join(*thd->td,(void *)&retval)) == 0) { + if ((stat = pthread_join(*thd->td,(void **)&thrstat)) == 0) { + if (retval != NULL && thrstat != NULL) + *retval = *thrstat; return APR_SUCCESS; } else { Index: srclib/apr/threadproc/win32/thread.c =================================================================== RCS file: /home/cvspublic/apr/threadproc/win32/thread.c,v retrieving revision 1.32 diff -u -r1.32 thread.c --- srclib/apr/threadproc/win32/thread.c 2001/07/06 14:20:03 1.32 +++ srclib/apr/threadproc/win32/thread.c 2001/07/20 00:17:49 @@ -97,25 +97,36 @@ apr_status_t stat; unsigned temp; int lasterror; + apr_thread_t *thread; + apr_thread_param_t *thrparm; - (*new) = (apr_thread_t *)apr_palloc(cont, sizeof(apr_thread_t)); + thread = (apr_thread_t *)apr_palloc(cont, sizeof(apr_thread_t)); + (*new) = thread; - if ((*new) == NULL) { + if (thread == NULL) { return APR_ENOMEM; } - (*new)->cntxt = cont; + thread->cntxt = cont; - stat = apr_pool_create(&(*new)->cntxt, cont); + stat = apr_pool_create(&thread->cntxt, cont); if (stat != APR_SUCCESS) { return stat; } + thrparm = (apr_thread_param_t *)apr_palloc(cont, sizeof(apr_thread_param_t)); + if (thrparm == NULL) { + return APR_ENOMEM; + } + + thrparm->t = thread; + thrparm->data = data; + /* Use 0 for Thread Stack Size, because that will default the stack to the * same size as the calling thread. */ - if (((*new)->td = (HANDLE *)_beginthreadex(NULL, 0, (unsigned int (APR_THREAD_FUNC *)(void *))func, - data, 0, &temp)) == 0) { + if ((thread->td = (HANDLE *)_beginthreadex(NULL, 0, (unsigned int (APR_THREAD_FUNC *)(void *))func, + thrparm, 0, &temp)) == 0) { lasterror = apr_get_os_error(); return APR_EEXIST; /* MSVC++ doc doesn't mention any additional error info @@ -124,7 +135,7 @@ } if (attr && attr->detach) { - CloseHandle((*new)->td); + CloseHandle(thread->td); } return APR_SUCCESS;