Only allow the semaphore to be taken when the value is positive.
Don't decrement it twice when it is taken. Reported by: kris
This commit is contained in:
parent
3ef89b60eb
commit
f8f3e115d3
@ -304,14 +304,13 @@ __sem_trywait(sem_t *sem)
|
||||
retval = ksem_trywait((*sem)->semid);
|
||||
else {
|
||||
_pthread_mutex_lock(&(*sem)->lock);
|
||||
if ((*sem)->count != 0) {
|
||||
if ((*sem)->count > 0) {
|
||||
(*sem)->count--;
|
||||
retval = 0;
|
||||
} else {
|
||||
errno = EAGAIN;
|
||||
retval = -1;
|
||||
}
|
||||
(*sem)->count--;
|
||||
_pthread_mutex_unlock(&(*sem)->lock);
|
||||
}
|
||||
return (retval);
|
||||
|
Loading…
Reference in New Issue
Block a user