diff options
Diffstat (limited to 'src/thread/sem_post.c')
-rw-r--r-- | src/thread/sem_post.c | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/src/thread/sem_post.c b/src/thread/sem_post.c index 8f4700c3..148ab780 100644 --- a/src/thread/sem_post.c +++ b/src/thread/sem_post.c @@ -3,8 +3,11 @@ int sem_post(sem_t *sem) { - a_inc(sem->__val); - if (sem->__val[1]) - __wake(sem->__val, 1, 0); + int val, waiters; + do { + val = sem->__val[0]; + waiters = sem->__val[1]; + } while (a_cas(sem->__val, val, val+1+(val<0)) != val); + if (val<0 || waiters) __wake(sem->__val, 1, 0); return 0; } |