Commit 8782f6d2 authored by Max Kellermann's avatar Max Kellermann

EventPipe: use Mutex instead of GMutex

parent 5faf4430
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#include "config.h" #include "config.h"
#include "EventPipe.hxx" #include "EventPipe.hxx"
#include "thread/Mutex.hxx"
#include "fd_util.h" #include "fd_util.h"
#include "mpd_error.h" #include "mpd_error.h"
...@@ -41,7 +42,7 @@ ...@@ -41,7 +42,7 @@
static int event_pipe[2]; static int event_pipe[2];
static GIOChannel *event_channel; static GIOChannel *event_channel;
static guint event_pipe_source_id; static guint event_pipe_source_id;
static GMutex *event_pipe_mutex; static Mutex event_pipe_mutex;
static bool pipe_events[PIPE_EVENT_MAX]; static bool pipe_events[PIPE_EVENT_MAX];
static event_pipe_callback_t event_pipe_callbacks[PIPE_EVENT_MAX]; static event_pipe_callback_t event_pipe_callbacks[PIPE_EVENT_MAX];
...@@ -72,10 +73,10 @@ main_notify_event(G_GNUC_UNUSED GIOChannel *source, ...@@ -72,10 +73,10 @@ main_notify_event(G_GNUC_UNUSED GIOChannel *source,
MPD_ERROR("error reading from pipe: %s", error->message); MPD_ERROR("error reading from pipe: %s", error->message);
bool events[PIPE_EVENT_MAX]; bool events[PIPE_EVENT_MAX];
g_mutex_lock(event_pipe_mutex); event_pipe_mutex.lock();
memcpy(events, pipe_events, sizeof(events)); memcpy(events, pipe_events, sizeof(events));
memset(pipe_events, 0, sizeof(pipe_events)); memset(pipe_events, 0, sizeof(pipe_events));
g_mutex_unlock(event_pipe_mutex); event_pipe_mutex.unlock();
for (unsigned i = 0; i < PIPE_EVENT_MAX; ++i) for (unsigned i = 0; i < PIPE_EVENT_MAX; ++i)
if (events[i]) if (events[i])
...@@ -106,14 +107,10 @@ void event_pipe_init(void) ...@@ -106,14 +107,10 @@ void event_pipe_init(void)
main_notify_event, NULL); main_notify_event, NULL);
event_channel = channel; event_channel = channel;
event_pipe_mutex = g_mutex_new();
} }
void event_pipe_deinit(void) void event_pipe_deinit(void)
{ {
g_mutex_free(event_pipe_mutex);
g_source_remove(event_pipe_source_id); g_source_remove(event_pipe_source_id);
g_io_channel_unref(event_channel); g_io_channel_unref(event_channel);
...@@ -139,15 +136,15 @@ void event_pipe_emit(enum pipe_event event) ...@@ -139,15 +136,15 @@ void event_pipe_emit(enum pipe_event event)
assert((unsigned)event < PIPE_EVENT_MAX); assert((unsigned)event < PIPE_EVENT_MAX);
g_mutex_lock(event_pipe_mutex); event_pipe_mutex.lock();
if (pipe_events[event]) { if (pipe_events[event]) {
/* already set: don't write */ /* already set: don't write */
g_mutex_unlock(event_pipe_mutex); event_pipe_mutex.unlock();
return; return;
} }
pipe_events[event] = true; pipe_events[event] = true;
g_mutex_unlock(event_pipe_mutex); event_pipe_mutex.unlock();
w = write(event_pipe[1], "", 1); w = write(event_pipe[1], "", 1);
if (w < 0 && errno != EAGAIN && errno != EINTR) if (w < 0 && errno != EAGAIN && errno != EINTR)
......
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