Loading...
pthreads.subproj/pthread_cond.c Libc-186 Libc-166
--- Libc/Libc-186/pthreads.subproj/pthread_cond.c
+++ Libc/Libc-166/pthreads.subproj/pthread_cond.c
@@ -78,7 +78,7 @@
 pthread_cond_broadcast(pthread_cond_t *cond)
 {
     kern_return_t kern_res;
-    int res;
+    int res, delta;
     if (cond->sig == _PTHREAD_COND_SIG_init) {
         if ((res = pthread_cond_init(cond, NULL)) != 0) {
             return (res);
@@ -89,16 +89,17 @@
         return (EINVAL);
     }
     LOCK(cond->lock);
-    if (cond->sem == MACH_PORT_NULL) {
-        /* Avoid kernel call since there are no waiters... */
+    delta = cond->waiters - cond->sigspending;
+    if (delta <= 0) {
+        /* Avoid kernel call since there are not enough waiters... */
         UNLOCK(cond->lock);
         return (ESUCCESS);
     }
-    cond->sigspending++;
+    cond->sigspending += delta;
     UNLOCK(cond->lock);
     PTHREAD_MACH_CALL(semaphore_signal_all(cond->sem), kern_res);
     LOCK(cond->lock);
-    cond->sigspending--;
+    cond->sigspending -= delta;
     if (cond->waiters == 0 && cond->sigspending == 0) {
         restore_sem_to_pool(cond->sem);
         cond->sem = MACH_PORT_NULL;
@@ -127,7 +128,7 @@
         return (EINVAL); /* Not a condition variable */
     }
     LOCK(cond->lock);
-    if (cond->sem == MACH_PORT_NULL) {
+    if (cond->waiters <= cond->sigspending) {
         /* Avoid kernel call since there are not enough waiters... */
         UNLOCK(cond->lock);
         return (ESUCCESS);
@@ -295,8 +296,7 @@
     if ((res = pthread_mutex_lock(mutex)) != ESUCCESS) {
         return (res);
     }
-    /* KERN_ABORTED can be treated as a spurious wakeup */
-    if ((kern_res == KERN_SUCCESS) || (kern_res == KERN_ABORTED)) {
+    if (kern_res == KERN_SUCCESS) {
         return (ESUCCESS);
     } else if (kern_res == KERN_OPERATION_TIMED_OUT) {
         return (ETIMEDOUT);