From 4f920f685bb4af8400c70383eecf347a35353778 Mon Sep 17 00:00:00 2001 From: David 'Digit' Turner Date: Fri, 12 Feb 2010 12:50:32 -0800 Subject: [PATCH] Fix sem_post() behaviour to wake up multiple waiting threads. --- libc/bionic/semaphore.c | 2 +- libc/docs/CHANGES.TXT | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/libc/bionic/semaphore.c b/libc/bionic/semaphore.c index f4eebce57..84b931479 100644 --- a/libc/bionic/semaphore.c +++ b/libc/bionic/semaphore.c @@ -180,7 +180,7 @@ int sem_post(sem_t *sem) if (sem == NULL) return EINVAL; - if (__atomic_inc((volatile int*)&sem->count) == 0) + if (__atomic_inc((volatile int*)&sem->count) >= 0) __futex_wake(&sem->count, 1); return 0; diff --git a/libc/docs/CHANGES.TXT b/libc/docs/CHANGES.TXT index 7c8f38c27..f59cfab63 100644 --- a/libc/docs/CHANGES.TXT +++ b/libc/docs/CHANGES.TXT @@ -55,6 +55,9 @@ Differences between current and Android 2.1: - fix sem_trywait() to return -1 and set errno to EAGAIN, instead of returning EAGAIN directly. +- fix sem_post() to wake up multiple threads when called rapidly in + succession. + ------------------------------------------------------------------------------- Differences between Android 2.1 and 2.0.1: