Преглед на файлове

fix pthread_join implementation

Samuel Thibault преди 15 години
родител
ревизия
f2e08abde9
променени са 1 файла, в които са добавени 17 реда и са изтрити 9 реда
  1. 17 9
      include/pthread_win32/pthread.h

+ 17 - 9
include/pthread_win32/pthread.h

@@ -130,16 +130,24 @@ static inline void pthread_exit (void *res) {
 }
 
 static inline int pthread_join (pthread_t thread, void **res) {
-  DWORD _res;
-
-  while (1) {
-    if (GetExitCodeThread(thread, &_res)) {
-      if (res) *res = (void *)_res;
-      return 0;
-    }
-    winPthreadAssertWindows(GetLastError() == STILL_ACTIVE);
-    Sleep(1);
+again:
+  switch (WaitForSingleObject(thread, INFINITE)) {
+    default:
+    case WAIT_FAILED:
+      setSystemErrno();
+      return errno;
+    case WAIT_ABANDONED:
+    case WAIT_OBJECT_0:
+      break;
+    case WAIT_TIMEOUT:
+      goto again;
+  }
+  if (res) {
+    DWORD _res;
+    if (GetExitCodeThread(thread, &_res))
+      *res = (void *)_res;
   }
+  return 0;
 }
 
 /***********