From 17b9298d9918a36c344741f20f165bc67b5b7769 Mon Sep 17 00:00:00 2001 From: rpj Date: Thu, 27 May 1999 20:44:42 +0000 Subject: Fri May 28 13:33:05 1999 Ross Johnson * condvar.c (pthread_cond_broadcast): Fix possible memory fault - Mark E. Armstrong Thu May 27 13:08:46 1999 Ross Johnson * condvar.c (pthread_cond_broadcast): Fix logic bug - Peter Slacik ; optimise sem_post loop - Bossom, John . --- condvar.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'condvar.c') diff --git a/condvar.c b/condvar.c index a77b56a..c1f192c 100644 --- a/condvar.c +++ b/condvar.c @@ -827,8 +827,6 @@ pthread_cond_broadcast (pthread_cond_t * cond) cv = *cond; - cv->wasBroadcast = TRUE; - /* * No-op if the CV is static and hasn't been initialised yet. */ @@ -837,13 +835,14 @@ pthread_cond_broadcast (pthread_cond_t * cond) return 0; } + cv->wasBroadcast = TRUE; + /* * Wake up all waiters */ - for (i = cv->waiters; i > 0 && result == 0; i--) - { - result = sem_post (&(cv->sema)); - } + result = (ReleaseSemaphore( cv->sema, cond->waiters, NULL ) + ? 0 + : EINVAL); if (cv->waiters > 0 && result == 0) { @@ -851,7 +850,7 @@ pthread_cond_broadcast (pthread_cond_t * cond) * Wait for all the awakened threads to acquire their part of * the counting semaphore */ - if (WaitForSingleObject (cv->waitersDone, INFINITE) != + if (WaitForSingleObject (cv->waitersDone, INFINITE) == WAIT_OBJECT_0) { result = 0; -- cgit v1.2.3