[Still trying to get the hang of this whole patch-submission/OSS project/ mailing list thing :) -- this patch should be *much* smaller] Update to APR thread API to explicitly pass the apr_thread_t to the worker function. Changed the worker routine's signature to take a single parameter: apr_thread_param_t, which contains the opaque data and the apr_thread_t. httpd-2.0 will have to be updated after applying this patch to APR. -aaron 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/21 06:43:58 @@ -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/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/21 06:43:58 @@ -94,6 +94,7 @@ { int32 temp; apr_status_t stat; + apr_thread_param_t *thrparm; (*new) = (apr_thread_t *)apr_palloc(cont, sizeof(apr_thread_t)); if ((*new) == NULL) { @@ -113,7 +114,14 @@ return stat; } - (*new)->td = spawn_thread((thread_func)func, "apr thread", temp, data); + thrparm = (apr_thread_param_t *)apr_palloc(cont, sizeof(apr_thread_param_t)); + if (thrparm == NULL) { + return APR_ENOMEM; + } + thrparm->t = (*new); + thrparm->data = data; + + (*new)->td = spawn_thread((thread_func)func, "apr thread", temp, thrparm); /* Now we try to run it...*/ if (resume_thread((*new)->td) == B_NO_ERROR) { return APR_SUCCESS; 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/21 06:43:59 @@ -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; 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/21 06:43:59 @@ -122,6 +122,7 @@ { apr_status_t stat; pthread_attr_t *temp; + apr_thread_param_t *thrparm; (*new) = (apr_thread_t *)apr_pcalloc(cont, sizeof(apr_thread_t)); @@ -147,7 +148,15 @@ return stat; } - if ((stat = pthread_create((*new)->td, temp, func, data)) == 0) { + thrparm = (apr_thread_param_t *)apr_pcalloc(cont, sizeof(apr_thread_param_t)); + if (thrparm == NULL) { + return APR_ENOMEM; + } + + thrparm->t = (*new); + thrparm->data = data; + + if ((stat = pthread_create((*new)->td, temp, (void*)func, thrparm)) == 0) { 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/21 06:43:59 @@ -97,6 +97,7 @@ apr_status_t stat; unsigned temp; int lasterror; + apr_thread_param_t *thrparm; (*new) = (apr_thread_t *)apr_palloc(cont, sizeof(apr_thread_t)); @@ -111,11 +112,19 @@ 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) { + thrparm, 0, &temp)) == 0) { lasterror = apr_get_os_error(); return APR_EEXIST; /* MSVC++ doc doesn't mention any additional error info