Commit ed9668f6 authored by Max Kellermann's avatar Max Kellermann

notify: use GLib locking

Use GLib locking (GMutex, GCond) instead of pthread because GLib is more portable, e.g. on mingw32.
parent e8c44782
...@@ -17,42 +17,33 @@ ...@@ -17,42 +17,33 @@
*/ */
#include "notify.h" #include "notify.h"
#include "log.h"
void notify_init(struct notify *notify) void notify_init(struct notify *notify)
{ {
int ret; notify->mutex = g_mutex_new();
notify->cond = g_cond_new();
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->pending = false; notify->pending = false;
} }
void notify_deinit(struct notify *notify) void notify_deinit(struct notify *notify)
{ {
pthread_mutex_destroy(&notify->mutex); g_mutex_free(notify->mutex);
pthread_cond_destroy(&notify->cond); g_cond_free(notify->cond);
} }
void notify_wait(struct notify *notify) void notify_wait(struct notify *notify)
{ {
pthread_mutex_lock(&notify->mutex); g_mutex_lock(notify->mutex);
while (!notify->pending) while (!notify->pending)
pthread_cond_wait(&notify->cond, &notify->mutex); g_cond_wait(notify->cond, notify->mutex);
notify->pending = false; notify->pending = false;
pthread_mutex_unlock(&notify->mutex); g_mutex_unlock(notify->mutex);
} }
void notify_signal(struct notify *notify) void notify_signal(struct notify *notify)
{ {
pthread_mutex_lock(&notify->mutex); g_mutex_lock(notify->mutex);
notify->pending = true; notify->pending = true;
pthread_cond_signal(&notify->cond); g_cond_signal(notify->cond);
pthread_mutex_unlock(&notify->mutex); g_mutex_unlock(notify->mutex);
} }
...@@ -19,20 +19,16 @@ ...@@ -19,20 +19,16 @@
#ifndef MPD_NOTIFY_H #ifndef MPD_NOTIFY_H
#define MPD_NOTIFY_H #define MPD_NOTIFY_H
#include <glib.h>
#include <stdbool.h> #include <stdbool.h>
#include <pthread.h>
struct notify { struct notify {
pthread_mutex_t mutex; GMutex *mutex;
pthread_cond_t cond; GCond *cond;
bool pending; bool pending;
}; };
#define NOTIFY_INITIALIZER { \
.mutex = PTHREAD_MUTEX_INITIALIZER, \
.cond = PTHREAD_COND_INITIALIZER, \
}
void notify_init(struct notify *notify); void notify_init(struct notify *notify);
void notify_deinit(struct notify *notify); void notify_deinit(struct notify *notify);
......
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
#include "pcm_utils.h" #include "pcm_utils.h"
#include "notify.h" #include "notify.h"
#include <pthread.h>
#include <time.h> #include <time.h>
struct audio_output { struct audio_output {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment