Merge "libutils: Clarify Condition::signal wakes up exactly one thread"

This commit is contained in:
Igor Murashkin 2014-04-15 22:50:02 +00:00 committed by Android (Google) Code Review
commit 8481765738
1 changed files with 12 additions and 1 deletions

View File

@ -60,7 +60,7 @@ public:
status_t wait(Mutex& mutex);
// same with relative timeout
status_t waitRelative(Mutex& mutex, nsecs_t reltime);
// Signal the condition variable, allowing one thread to continue.
// Signal the condition variable, allowing exactly one thread to continue.
void signal();
// Signal the condition variable, allowing one or all threads to continue.
void signal(WakeUpType type) {
@ -132,6 +132,17 @@ inline status_t Condition::waitRelative(Mutex& mutex, nsecs_t reltime) {
#endif // HAVE_PTHREAD_COND_TIMEDWAIT_RELATIVE
}
inline void Condition::signal() {
/*
* POSIX says pthread_cond_signal wakes up "one or more" waiting threads.
* However bionic follows the glibc guarantee which wakes up "exactly one"
* waiting thread.
*
* man 3 pthread_cond_signal
* pthread_cond_signal restarts one of the threads that are waiting on
* the condition variable cond. If no threads are waiting on cond,
* nothing happens. If several threads are waiting on cond, exactly one
* is restarted, but it is not specified which.
*/
pthread_cond_signal(&mCond);
}
inline void Condition::broadcast() {