aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2009-01-02 11:20:41 +0100
committerMax Kellermann <max@duempel.org>2009-01-02 11:20:41 +0100
commit272ee5f7d2be764d5edef2db763f50438689b48c (patch)
tree871f80692a7f9f1d2f02173fc49d1183819eae55
parentdaf7c3db5aac09a8376f1c8ed499eb17202f77a9 (diff)
downloadmpd-272ee5f7d2be764d5edef2db763f50438689b48c.tar.gz
mpd-272ee5f7d2be764d5edef2db763f50438689b48c.tar.xz
mpd-272ee5f7d2be764d5edef2db763f50438689b48c.zip
event_pipe: replaced PIPE_EVENT_SIGNAL with main_notify
There is only one location using PIPE_EVENT_SIGNAL: to synchronize player_command() with player_command_finished(). Use the "notify" library instead of the event_pipe here.
-rw-r--r--src/event_pipe.c18
-rw-r--r--src/event_pipe.h6
-rw-r--r--src/main.c3
-rw-r--r--src/main.h2
-rw-r--r--src/player_control.c4
-rw-r--r--src/player_thread.c3
6 files changed, 13 insertions, 23 deletions
diff --git a/src/event_pipe.c b/src/event_pipe.c
index 318e59df6..8d9a7fed3 100644
--- a/src/event_pipe.c
+++ b/src/event_pipe.c
@@ -39,13 +39,13 @@ static void
event_pipe_invoke(enum pipe_event event)
{
assert((unsigned)event < PIPE_EVENT_MAX);
- assert(event != PIPE_EVENT_SIGNAL);
assert(event_pipe_callbacks[event] != NULL);
event_pipe_callbacks[event]();
}
-static bool consume_pipe(void)
+static void
+consume_pipe(void)
{
char buffer[256];
ssize_t r = read(event_pipe[0], buffer, sizeof(buffer));
@@ -60,13 +60,9 @@ static bool consume_pipe(void)
g_mutex_unlock(event_pipe_mutex);
for (unsigned i = 0; i < PIPE_EVENT_MAX; ++i)
- if (i != PIPE_EVENT_SIGNAL && events[i])
- /* invoke the event handler; the SIGNAL event
- has no handler, because it is handled by
- the event_pipe_wait() caller */
+ if (events[i])
+ /* invoke the event handler */
event_pipe_invoke(i);
-
- return events[PIPE_EVENT_SIGNAL];
}
static gboolean
@@ -109,7 +105,6 @@ void event_pipe_deinit(void)
void
event_pipe_register(enum pipe_event event, event_pipe_callback_t callback)
{
- assert(event != PIPE_EVENT_SIGNAL);
assert((unsigned)event < PIPE_EVENT_MAX);
assert(event_pipe_callbacks[event] == NULL);
@@ -145,11 +140,6 @@ void event_pipe_emit_fast(enum pipe_event event)
write(event_pipe[1], "", 1);
}
-void event_pipe_signal(void)
-{
- event_pipe_emit(PIPE_EVENT_SIGNAL);
-}
-
void event_pipe_wait(void)
{
consume_pipe();
diff --git a/src/event_pipe.h b/src/event_pipe.h
index 3888939c8..6205ab867 100644
--- a/src/event_pipe.h
+++ b/src/event_pipe.h
@@ -24,10 +24,6 @@
#include <glib.h>
enum pipe_event {
- /** the default event: the main thread is waiting for somebody,
- and this event wakes up the main thread */
- PIPE_EVENT_SIGNAL = 0,
-
/** database update was finished */
PIPE_EVENT_UPDATE,
@@ -66,8 +62,6 @@ void event_pipe_emit(enum pipe_event event);
*/
void event_pipe_emit_fast(enum pipe_event event);
-void event_pipe_signal(void);
-
void event_pipe_wait(void);
#endif /* MAIN_NOTIFY_H */
diff --git a/src/main.c b/src/main.c
index aec3e92e9..c6e81f461 100644
--- a/src/main.c
+++ b/src/main.c
@@ -77,6 +77,8 @@
GMainLoop *main_loop;
+struct notify main_notify;
+
static void changeToUser(void)
{
#ifndef WIN32
@@ -240,6 +242,7 @@ int main(int argc, char *argv[])
changeToUser();
main_loop = g_main_loop_new(NULL, FALSE);
+ notify_init(&main_notify);
event_pipe_init();
event_pipe_register(PIPE_EVENT_IDLE, idle_event_emitted);
diff --git a/src/main.h b/src/main.h
index 8943280a1..0db289267 100644
--- a/src/main.h
+++ b/src/main.h
@@ -21,4 +21,6 @@
extern GMainLoop *main_loop;
+extern struct notify main_notify;
+
#endif
diff --git a/src/player_control.c b/src/player_control.c
index 63ed75f7b..bb687f8ad 100644
--- a/src/player_control.c
+++ b/src/player_control.c
@@ -23,7 +23,7 @@
#include "song.h"
#include "idle.h"
#include "pcm_utils.h"
-#include "event_pipe.h"
+#include "main.h"
#include <assert.h>
#include <stdio.h>
@@ -58,7 +58,7 @@ static void player_command(enum player_command cmd)
pc.command = cmd;
while (pc.command != PLAYER_COMMAND_NONE) {
notify_signal(&pc.notify);
- event_pipe_wait();
+ notify_wait(&main_notify);
}
}
diff --git a/src/player_thread.c b/src/player_thread.c
index 5b2130669..5ca5b5b02 100644
--- a/src/player_thread.c
+++ b/src/player_thread.c
@@ -27,6 +27,7 @@
#include "song.h"
#include "pipe.h"
#include "idle.h"
+#include "main.h"
#include <glib.h>
@@ -83,7 +84,7 @@ static void player_command_finished(void)
assert(pc.command != PLAYER_COMMAND_NONE);
pc.command = PLAYER_COMMAND_NONE;
- event_pipe_signal();
+ notify_signal(&main_notify);
}
static void player_stop_decoder(void)