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.
This commit is contained in:
Max Kellermann 2009-01-02 11:20:41 +01:00
parent daf7c3db5a
commit 272ee5f7d2
6 changed files with 13 additions and 23 deletions

View File

@ -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();

View File

@ -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 */

View File

@ -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);

View File

@ -21,4 +21,6 @@
extern GMainLoop *main_loop;
extern struct notify main_notify;
#endif

View File

@ -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);
}
}

View File

@ -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)