notify: protect notify->pending with the mutex
There was a known deadlocking bug in the notify library: when the other thread set notify->pending after the according check in notify_wait(), the latter thread was deadlocked. Resolve this by synchronizing all accesses to notify->pending with the notify object's mutex. Since notify_signal_sync() was never used, we can remove it. As a consequence, we don't need notify_enter() and notify_leave() anymore; eliminate them, too.
This commit is contained in:
20
src/notify.c
20
src/notify.c
@@ -40,32 +40,20 @@ void notify_deinit(struct notify *notify)
|
||||
pthread_cond_destroy(¬ify->cond);
|
||||
}
|
||||
|
||||
void notify_enter(struct notify *notify)
|
||||
{
|
||||
pthread_mutex_lock(¬ify->mutex);
|
||||
}
|
||||
|
||||
void notify_leave(struct notify *notify)
|
||||
{
|
||||
pthread_mutex_unlock(¬ify->mutex);
|
||||
}
|
||||
|
||||
void notify_wait(struct notify *notify)
|
||||
{
|
||||
pthread_mutex_lock(¬ify->mutex);
|
||||
if (!notify->pending)
|
||||
pthread_cond_wait(¬ify->cond, ¬ify->mutex);
|
||||
assert(notify->pending);
|
||||
notify->pending = 0;
|
||||
pthread_mutex_unlock(¬ify->mutex);
|
||||
}
|
||||
|
||||
void notify_signal(struct notify *notify)
|
||||
{
|
||||
pthread_mutex_lock(¬ify->mutex);
|
||||
notify->pending = 1;
|
||||
pthread_cond_signal(¬ify->cond);
|
||||
}
|
||||
|
||||
void notify_signal_sync(struct notify *notify)
|
||||
{
|
||||
pthread_mutex_lock(¬ify->mutex);
|
||||
notify_signal(notify);
|
||||
pthread_mutex_unlock(¬ify->mutex);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user