Return-Path: Delivered-To: apmail-apr-dev-archive@apr.apache.org Received: (qmail 43181 invoked by uid 500); 24 Sep 2001 22:25:30 -0000 Mailing-List: contact dev-help@apr.apache.org; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: Delivered-To: mailing list dev@apr.apache.org Received: (qmail 43170 invoked from network); 24 Sep 2001 22:25:30 -0000 Date: Mon, 24 Sep 2001 15:25:28 -0700 From: Aaron Bannert To: dev@apr.apache.org Subject: [PATCH] fix apr_thread_exit() param type to be usable Message-ID: <20010924152528.I20983@clove.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5i X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N apr_thread_exit() takes a parameter signaling the return status of the thread as it is exiting. This patch change the parameter from a pointer-to-apr_status_t to just an apr_status_t. The reason for this is that the return value cannot* be allocated from heapspace, since the only heapspace available to the thread right then is about to be destroyed. (* Unless you do something gross like use a global pool or a static, but that defeats the whole purpose of thread-specific pools.) This patch passes the modified testthread program on UNIX. I'm not so sure about the semantics of the various other platforms, but the changes in this patch are small enough that they can be reviewed easily by our platform gurus. This patch will have to be applied with a [small] patch to httpd-2.0 so we don't break the build over there. If I can get a +1 from someone on each platform {beos,netware,os2,win32} then I'll produce the httpd patch and we can proceed from there. -aaron Index: include/apr_thread_proc.h =================================================================== RCS file: /home/cvspublic/apr/include/apr_thread_proc.h,v retrieving revision 1.75 diff -u -r1.75 apr_thread_proc.h --- include/apr_thread_proc.h 2001/09/20 08:59:30 1.75 +++ include/apr_thread_proc.h 2001/09/24 22:10:54 @@ -216,7 +216,7 @@ * @param retval The return value to pass back to any thread that cares */ APR_DECLARE(apr_status_t) apr_thread_exit(apr_thread_t *thd, - apr_status_t *retval); + apr_status_t retval); /** * block until the desired thread stops executing. Index: include/arch/beos/threadproc.h =================================================================== RCS file: /home/cvspublic/apr/include/arch/beos/threadproc.h,v retrieving revision 1.19 diff -u -r1.19 threadproc.h --- include/arch/beos/threadproc.h 2001/09/11 13:33:39 1.19 +++ include/arch/beos/threadproc.h 2001/09/24 22:10:54 @@ -82,6 +82,7 @@ thread_id td; void *data; apr_thread_start_t func; + apr_status_t rv; }; struct apr_threadattr_t { Index: include/arch/netware/threadproc.h =================================================================== RCS file: /home/cvspublic/apr/include/arch/netware/threadproc.h,v retrieving revision 1.2 diff -u -r1.2 threadproc.h --- include/arch/netware/threadproc.h 2001/09/10 22:39:37 1.2 +++ include/arch/netware/threadproc.h 2001/09/24 22:10:54 @@ -67,6 +67,7 @@ apr_pool_t *cntxt; NXContext_t ctx; NXThreadId_t td; + apr_status_t rv; }; struct apr_threadattr_t { Index: include/arch/unix/threadproc.h =================================================================== RCS file: /home/cvspublic/apr/include/arch/unix/threadproc.h,v retrieving revision 1.20 diff -u -r1.20 threadproc.h --- include/arch/unix/threadproc.h 2001/08/27 03:17:15 1.20 +++ include/arch/unix/threadproc.h 2001/09/24 22:10:54 @@ -92,6 +92,7 @@ pthread_t *td; void *data; apr_thread_start_t func; + apr_status_t rv; }; struct apr_threadattr_t { Index: include/arch/win32/threadproc.h =================================================================== RCS file: /home/cvspublic/apr/include/arch/win32/threadproc.h,v retrieving revision 1.16 diff -u -r1.16 threadproc.h --- include/arch/win32/threadproc.h 2001/09/09 06:03:05 1.16 +++ include/arch/win32/threadproc.h 2001/09/24 22:10:55 @@ -68,6 +68,7 @@ apr_int32_t cancel_how; void *data; apr_thread_start_t func; + apr_status_t rv; }; struct apr_threadattr_t { Index: test/testthread.c =================================================================== RCS file: /home/cvspublic/apr/test/testthread.c,v retrieving revision 1.24 diff -u -r1.24 testthread.c --- test/testthread.c 2001/09/02 03:41:17 1.24 +++ test/testthread.c 2001/09/24 22:10:55 @@ -102,7 +102,7 @@ x++; apr_lock_release(thread_lock); } - apr_thread_exit(thd, &exit_ret_val); + apr_thread_exit(thd, exit_ret_val); return NULL; } @@ -117,7 +117,7 @@ x++; apr_lock_release(thread_lock); } - apr_thread_exit(thd, &exit_ret_val); + apr_thread_exit(thd, exit_ret_val); return NULL; } @@ -132,7 +132,7 @@ x++; apr_lock_release(thread_lock); } - apr_thread_exit(thd, &exit_ret_val); + apr_thread_exit(thd, exit_ret_val); return NULL; } @@ -147,7 +147,7 @@ x++; apr_lock_release(thread_lock); } - apr_thread_exit(thd, &exit_ret_val); + apr_thread_exit(thd, exit_ret_val); return NULL; } Index: threadproc/beos/thread.c =================================================================== RCS file: /home/cvspublic/apr/threadproc/beos/thread.c,v retrieving revision 1.27 diff -u -r1.27 thread.c --- threadproc/beos/thread.c 2001/09/11 13:33:39 1.27 +++ threadproc/beos/thread.c 2001/09/24 22:10:55 @@ -141,18 +141,20 @@ return tid1 == tid2; } -APR_DECLARE(apr_status_t) apr_thread_exit(apr_thread_t *thd, apr_status_t *retval) +APR_DECLARE(apr_status_t) apr_thread_exit(apr_thread_t *thd, apr_status_t retval) { + thd->rv = retval; apr_pool_destroy(thd->cntxt); - exit_thread ((status_t)(*retval)); + exit_thread(NULL); return APR_SUCCESS; } APR_DECLARE(apr_status_t) apr_thread_join(apr_status_t *retval, apr_thread_t *thd) { - status_t rv = 0, ret; - if ((ret = wait_for_thread(thd->td,&rv)) == B_NO_ERROR) { - *retval = rv; + status_t ret; + /* FIXME: Is it ok to pass in a NULL as the retval? */ + if ((ret = wait_for_thread(thd->td, NULL)) == B_NO_ERROR) { + *retval = thd->rv; return APR_SUCCESS; } else { Index: threadproc/netware/thread.c =================================================================== RCS file: /home/cvspublic/apr/threadproc/netware/thread.c,v retrieving revision 1.4 diff -u -r1.4 thread.c --- threadproc/netware/thread.c 2001/09/10 22:42:22 1.4 +++ threadproc/netware/thread.c 2001/09/24 22:10:56 @@ -175,10 +175,11 @@ } apr_status_t apr_thread_exit(apr_thread_t *thd, - apr_status_t *retval) + apr_status_t retval) { + thd->rv = retval; apr_pool_destroy(thd->cntxt); - NXThreadExit((void *)*retval); + NXThreadExit(NULL); return APR_SUCCESS; } @@ -188,7 +189,8 @@ apr_status_t stat; NXThreadId_t dthr; - if ((stat = NXThreadJoin(thd->td, &dthr, (void *)&retval)) == 0) { + if ((stat = NXThreadJoin(thd->td, &dthr, NULL)) == 0) { + *retval = thd->rv; return APR_SUCCESS; } else { @@ -253,4 +255,4 @@ return APR_SUCCESS; } -*/ \ No newline at end of file +*/ Index: threadproc/os2/thread.c =================================================================== RCS file: /home/cvspublic/apr/threadproc/os2/thread.c,v retrieving revision 1.29 diff -u -r1.29 thread.c --- threadproc/os2/thread.c 2001/09/02 05:34:55 1.29 +++ threadproc/os2/thread.c 2001/09/24 22:10:56 @@ -154,9 +154,9 @@ -APR_DECLARE(apr_status_t) apr_thread_exit(apr_thread_t *thd, apr_status_t *retval) +APR_DECLARE(apr_status_t) apr_thread_exit(apr_thread_t *thd, apr_status_t retval) { - thd->rv = *retval; + thd->rv = retval; _endthread(); return -1; /* If we get here something's wrong */ } @@ -176,7 +176,7 @@ if (rc == ERROR_INVALID_THREADID) rc = 0; /* Thread had already terminated */ - *retval = (apr_status_t)thd->rv; + *retval = thd->rv; return APR_OS2_STATUS(rc); } Index: threadproc/unix/thread.c =================================================================== RCS file: /home/cvspublic/apr/threadproc/unix/thread.c,v retrieving revision 1.48 diff -u -r1.48 thread.c --- threadproc/unix/thread.c 2001/09/02 03:44:37 1.48 +++ threadproc/unix/thread.c 2001/09/24 22:10:56 @@ -176,10 +176,11 @@ return pthread_equal(tid1, tid2); } -APR_DECLARE(apr_status_t) apr_thread_exit(apr_thread_t *thd, apr_status_t *retval) +APR_DECLARE(apr_status_t) apr_thread_exit(apr_thread_t *thd, apr_status_t retval) { + thd->rv = retval; apr_pool_destroy(thd->cntxt); - pthread_exit(retval); + pthread_exit(NULL); return APR_SUCCESS; } @@ -189,7 +190,7 @@ apr_status_t *thread_stat; if ((stat = pthread_join(*thd->td,(void *)&thread_stat)) == 0) { - *retval = thread_stat ? *thread_stat : APR_SUCCESS; + *retval = thd->rv; return APR_SUCCESS; } else { Index: threadproc/win32/thread.c =================================================================== RCS file: /home/cvspublic/apr/threadproc/win32/thread.c,v retrieving revision 1.39 diff -u -r1.39 thread.c --- threadproc/win32/thread.c 2001/09/01 16:48:58 1.39 +++ threadproc/win32/thread.c 2001/09/24 22:10:56 @@ -140,10 +140,11 @@ } APR_DECLARE(apr_status_t) apr_thread_exit(apr_thread_t *thd, - apr_status_t *retval) + apr_status_t retval) { + thd->rv = retval; apr_pool_destroy(thd->cntxt); - _endthreadex(*retval); + _endthreadex(NULL); return APR_SUCCESS; } @@ -153,10 +154,8 @@ apr_status_t stat; if ((stat = WaitForSingleObject(thd->td, INFINITE)) == WAIT_OBJECT_0) { - if (GetExitCodeThread(thd->td, retval) == 0) { - return APR_SUCCESS; - } - return apr_get_os_error(); + *retval = thd->rv; + return APR_SUCCESS; } else { return stat;