apr-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mladen Turk <mt...@apache.org>
Subject [PATCH] WIN32 - fix apr_thread_join (PR: 28460) - v.3
Date Sat, 28 Aug 2004 07:11:45 GMT

Take 3 for the thread_join fix :).
This one behaves like on *nix when thread_join
is called on a thread without thread_exit called.

My FreeBSD 4.10 with ngpt-1.0.1 simply
returns APR_SUCCESS and sets the exitval to 0.

Other comments are the same as for the previous post.



Index: thread.c
===================================================================
RCS file: /home/cvspublic/apr/threadproc/win32/thread.c,v
retrieving revision 1.57
diff -u -r1.57 thread.c
--- thread.c	10 Jun 2004 10:57:25 -0000	1.57
+++ thread.c	28 Aug 2004 06:46:51 -0000
@@ -85,8 +85,9 @@
  {
      apr_status_t stat;
  	unsigned temp;
+    HANDLE handle;

-    (*new) = (apr_thread_t *)apr_palloc(pool, sizeof(apr_thread_t));
+    (*new) = (apr_thread_t *)apr_pcalloc(pool, sizeof(apr_thread_t));

      if ((*new) == NULL) {
          return APR_ENOMEM;
@@ -105,14 +106,14 @@
       * same size as the calling thread.
       */
  #ifndef _WIN32_WCE
-    if (((*new)->td = (HANDLE)_beginthreadex(NULL,
+    if ((handle = (HANDLE)_beginthreadex(NULL,
                          attr && attr->stacksize > 0 ? attr->stacksize :
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,
+   if ((handle = CreateThread(NULL,
                          attr && attr->stacksize > 0 ? attr->stacksize :
0,
                          (unsigned int (APR_THREAD_FUNC *)(void 
*))dummy_worker,
                          (*new), 0, &temp)) == 0) {
@@ -120,9 +121,10 @@
      }
  #endif
      if (attr && attr->detach) {
-        CloseHandle((*new)->td);
-        (*new)->td = NULL;
+        CloseHandle(handle);
      }
+    else
+        (*new)->td = handle;

      return APR_SUCCESS;
  }
@@ -132,10 +134,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);
@@ -146,15 +146,22 @@
  APR_DECLARE(apr_status_t) apr_thread_join(apr_status_t *retval,
                                            apr_thread_t *thd)
  {
-    apr_status_t rv;
-
+    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) {
          *retval = thd->exitval;
-        return APR_SUCCESS;
      }
-    /* Wait failed */
-    return apr_get_os_error();;
+    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)


Regards,
MT.


Mime
View raw message