aboutsummaryrefslogtreecommitdiffstats
path: root/src/notify.c
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2008-09-26 09:57:11 +0200
committerMax Kellermann <max@duempel.org>2008-09-26 09:57:11 +0200
commit58554e14f9995fdafe2338a69a42d9192b96f712 (patch)
tree83881d1e2131795581c822aa5cd01ddce42cf80f /src/notify.c
parent323e86489fb9544b3a2faa9e9004ac0b72bf01ca (diff)
downloadmpd-58554e14f9995fdafe2338a69a42d9192b96f712.tar.gz
mpd-58554e14f9995fdafe2338a69a42d9192b96f712.tar.xz
mpd-58554e14f9995fdafe2338a69a42d9192b96f712.zip
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.
Diffstat (limited to 'src/notify.c')
-rw-r--r--src/notify.c20
1 files changed, 4 insertions, 16 deletions
diff --git a/src/notify.c b/src/notify.c
index edb77f66d..5aaecd0ad 100644
--- a/src/notify.c
+++ b/src/notify.c
@@ -40,32 +40,20 @@ void notify_deinit(struct notify *notify)
pthread_cond_destroy(&notify->cond);
}
-void notify_enter(struct notify *notify)
-{
- pthread_mutex_lock(&notify->mutex);
-}
-
-void notify_leave(struct notify *notify)
-{
- pthread_mutex_unlock(&notify->mutex);
-}
-
void notify_wait(struct notify *notify)
{
+ pthread_mutex_lock(&notify->mutex);
if (!notify->pending)
pthread_cond_wait(&notify->cond, &notify->mutex);
+ assert(notify->pending);
notify->pending = 0;
+ pthread_mutex_unlock(&notify->mutex);
}
void notify_signal(struct notify *notify)
{
+ pthread_mutex_lock(&notify->mutex);
notify->pending = 1;
pthread_cond_signal(&notify->cond);
-}
-
-void notify_signal_sync(struct notify *notify)
-{
- pthread_mutex_lock(&notify->mutex);
- notify_signal(notify);
pthread_mutex_unlock(&notify->mutex);
}