Return-Path: Delivered-To: apmail-apr-cvs-archive@www.apache.org Received: (qmail 52302 invoked from network); 23 Sep 2004 06:18:04 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur-2.apache.org with SMTP; 23 Sep 2004 06:18:04 -0000 Received: (qmail 98067 invoked by uid 500); 23 Sep 2004 06:18:02 -0000 Delivered-To: apmail-apr-cvs-archive@apr.apache.org Received: (qmail 98030 invoked by uid 500); 23 Sep 2004 06:18:01 -0000 Mailing-List: contact cvs-help@apr.apache.org; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: Reply-To: dev@apr.apache.org Delivered-To: mailing list cvs@apr.apache.org Received: (qmail 98016 invoked by uid 99); 23 Sep 2004 06:18:01 -0000 X-ASF-Spam-Status: No, hits=-10.0 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Date: 23 Sep 2004 06:17:59 -0000 Message-ID: <20040923061759.52239.qmail@minotaur.apache.org> From: mturk@apache.org To: apr-cvs@apache.org Subject: cvs commit: apr/threadproc/win32 thread.c X-Virus-Checked: Checked X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N mturk 2004/09/22 23:17:59 Modified: threadproc/win32 Tag: APR_0_9_BRANCH thread.c Log: Backport from HEAD. Makes the threads to behave like on posix. If the thread is created without APR_DETACH expect that the thread_join will be called, so don't close the handle in advance, if the thread has already finished. Reviewed by: wrowe Revision Changes Path No revision No revision 1.54.2.2 +32 -18 apr/threadproc/win32/thread.c Index: thread.c =================================================================== RCS file: /home/cvs/apr/threadproc/win32/thread.c,v retrieving revision 1.54.2.1 retrieving revision 1.54.2.2 diff -u -r1.54.2.1 -r1.54.2.2 --- thread.c 13 Feb 2004 09:33:55 -0000 1.54.2.1 +++ thread.c 23 Sep 2004 06:17:59 -0000 1.54.2.2 @@ -38,6 +38,8 @@ } (*new)->pool = pool; + (*new)->detach = 0; + return APR_SUCCESS; } @@ -69,7 +71,8 @@ { apr_status_t stat; unsigned temp; - + HANDLE handle; + (*new) = (apr_thread_t *)apr_palloc(pool, sizeof(apr_thread_t)); if ((*new) == NULL) { @@ -79,7 +82,8 @@ (*new)->pool = pool; (*new)->data = data; (*new)->func = func; - + (*new)->td = NULL; + stat = apr_pool_create(&(*new)->pool, pool); if (stat != APR_SUCCESS) { return stat; @@ -89,22 +93,23 @@ * same size as the calling thread. */ #ifndef _WIN32_WCE - if (((*new)->td = (HANDLE)_beginthreadex(NULL, 0, + if ((handle = (HANDLE)_beginthreadex(NULL, 0, (unsigned int (APR_THREAD_FUNC *)(void *))dummy_worker, (*new), 0, &temp)) == 0) { return APR_FROM_OS_ERROR(_doserrno); } #else - if (((*new)->td = CreateThread(NULL, 0, + if ((handle = CreateThread(NULL, 0, (unsigned int (APR_THREAD_FUNC *)(void *))dummy_worker, (*new), 0, &temp)) == 0) { return apr_get_os_error(); } #endif if (attr && attr->detach) { - CloseHandle((*new)->td); - (*new)->td = NULL; + CloseHandle(handle); } + else + (*new)->td = handle; return APR_SUCCESS; } @@ -114,10 +119,8 @@ { thd->exitval = retval; apr_pool_destroy(thd->pool); + thd->pool = NULL; #ifndef _WIN32_WCE - if (thd->td) { - CloseHandle(thd->td); - } _endthreadex(0); #else ExitThread(0); @@ -128,15 +131,26 @@ APR_DECLARE(apr_status_t) apr_thread_join(apr_status_t *retval, apr_thread_t *thd) { - apr_status_t rv; - - rv = WaitForSingleObject(thd->td, INFINITE); - if ( rv == WAIT_OBJECT_0 || rv == WAIT_ABANDONED) { - *retval = thd->exitval; - return APR_SUCCESS; - } - /* Wait failed */ - return apr_get_os_error();; + apr_status_t rv = APR_SUCCESS; + + if (!thd->td) { + /* Can not join on detached threads */ + return APR_DETACH; + } + rv = WaitForSingleObject(thd->td, INFINITE); + if ( rv == WAIT_OBJECT_0 || rv == WAIT_ABANDONED) { + /* If the thread_exit has been called */ + if (!thd->pool) + *retval = thd->exitval; + else + rv = APR_INCOMPLETE; + } + else + rv = apr_get_os_error(); + CloseHandle(thd->td); + thd->td = NULL; + + return rv; } APR_DECLARE(apr_status_t) apr_thread_detach(apr_thread_t *thd)