major semaphore improvements (performance and correctness)

1. make sem_[timed]wait interruptible by signals, per POSIX
2. keep a waiter count in order to avoid unnecessary futex wake syscalls
This commit is contained in:
Rich Felker
2011-04-06 12:24:34 -04:00
parent cd3bb38412
commit a113434cd6
5 changed files with 37 additions and 21 deletions

View File

@ -3,9 +3,8 @@
int sem_trywait(sem_t *sem)
{
int val = a_fetch_add(sem->__val, -1);
if (val > 0) return 0;
if (!a_fetch_add(sem->__val, 1))
if (a_fetch_add(sem->__val, -1) > 0) return 0;
if (!a_fetch_add(sem->__val, 1) && sem->__val[1])
__wake(sem->__val, 1, 0);
errno = EAGAIN;
return -1;