Don't release the semaphore, if no one is waiting on the condition

variable. pthread_cond_broadcast() incorrectly returned an error
when no one was waiting.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@27253 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Ingo Weinhold 2008-08-31 13:41:52 +00:00
parent fbed358934
commit ce2a6a4bed
1 changed files with 9 additions and 2 deletions

View File

@ -120,11 +120,18 @@ cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex, bigtime_t timeout)
static status_t
cond_signal(pthread_cond_t *cond, bool broadcast)
{
int32 waiterCount;
if (cond == NULL)
return B_BAD_VALUE;
atomic_add((vint32*)&cond->event_counter, 1);
return release_sem_etc(cond->sem, broadcast ? cond->waiter_count : 1, 0);
waiterCount = cond->waiter_count;
if (waiterCount > 0) {
atomic_add((vint32*)&cond->event_counter, 1);
return release_sem_etc(cond->sem, broadcast ? waiterCount : 1, 0);
}
return 0;
}