aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2008-12-27 20:56:06 +0100
committerMax Kellermann <max@duempel.org>2008-12-27 20:56:06 +0100
commited9668f638ec3a31096821648f289b8a243f4ab2 (patch)
tree4ef39af2684f7aea0d4608f3413b68b7eb5b71a5
parente8c44782d0014ac72c155616a3b3272824b2ff96 (diff)
downloadmpd-ed9668f638ec3a31096821648f289b8a243f4ab2.tar.gz
mpd-ed9668f638ec3a31096821648f289b8a243f4ab2.tar.xz
mpd-ed9668f638ec3a31096821648f289b8a243f4ab2.zip
notify: use GLib locking
Use GLib locking (GMutex, GCond) instead of pthread because GLib is more portable, e.g. on mingw32.
Diffstat (limited to '')
-rw-r--r--src/notify.c29
-rw-r--r--src/notify.h12
-rw-r--r--src/output_internal.h1
3 files changed, 15 insertions, 27 deletions
diff --git a/src/notify.c b/src/notify.c
index 7d25db517..24d0e3928 100644
--- a/src/notify.c
+++ b/src/notify.c
@@ -17,42 +17,33 @@
*/
#include "notify.h"
-#include "log.h"
void notify_init(struct notify *notify)
{
- int ret;
-
- ret = pthread_mutex_init(&notify->mutex, NULL);
- if (ret != 0)
- FATAL("pthread_mutex_init() failed");
-
- ret = pthread_cond_init(&notify->cond, NULL);
- if (ret != 0)
- FATAL("pthread_mutex_init() failed");
-
+ notify->mutex = g_mutex_new();
+ notify->cond = g_cond_new();
notify->pending = false;
}
void notify_deinit(struct notify *notify)
{
- pthread_mutex_destroy(&notify->mutex);
- pthread_cond_destroy(&notify->cond);
+ g_mutex_free(notify->mutex);
+ g_cond_free(notify->cond);
}
void notify_wait(struct notify *notify)
{
- pthread_mutex_lock(&notify->mutex);
+ g_mutex_lock(notify->mutex);
while (!notify->pending)
- pthread_cond_wait(&notify->cond, &notify->mutex);
+ g_cond_wait(notify->cond, notify->mutex);
notify->pending = false;
- pthread_mutex_unlock(&notify->mutex);
+ g_mutex_unlock(notify->mutex);
}
void notify_signal(struct notify *notify)
{
- pthread_mutex_lock(&notify->mutex);
+ g_mutex_lock(notify->mutex);
notify->pending = true;
- pthread_cond_signal(&notify->cond);
- pthread_mutex_unlock(&notify->mutex);
+ g_cond_signal(notify->cond);
+ g_mutex_unlock(notify->mutex);
}
diff --git a/src/notify.h b/src/notify.h
index 13b7dbe2e..cb4815357 100644
--- a/src/notify.h
+++ b/src/notify.h
@@ -19,20 +19,16 @@
#ifndef MPD_NOTIFY_H
#define MPD_NOTIFY_H
+#include <glib.h>
+
#include <stdbool.h>
-#include <pthread.h>
struct notify {
- pthread_mutex_t mutex;
- pthread_cond_t cond;
+ GMutex *mutex;
+ GCond *cond;
bool pending;
};
-#define NOTIFY_INITIALIZER { \
- .mutex = PTHREAD_MUTEX_INITIALIZER, \
- .cond = PTHREAD_COND_INITIALIZER, \
-}
-
void notify_init(struct notify *notify);
void notify_deinit(struct notify *notify);
diff --git a/src/output_internal.h b/src/output_internal.h
index cea1455e3..b71508ff7 100644
--- a/src/output_internal.h
+++ b/src/output_internal.h
@@ -23,6 +23,7 @@
#include "pcm_utils.h"
#include "notify.h"
+#include <pthread.h>
#include <time.h>
struct audio_output {