From 57de90e3b8958b4d5edf1bd0145f98623768caa9 Mon Sep 17 00:00:00 2001 From: waker Date: Wed, 30 Mar 2011 22:22:56 +0200 Subject: get rid of frameupdate event; mutex+cond based message pump without usleep --- deadbeef.h | 1 - main.c | 5 +++-- messagepump.c | 10 ++++++++++ messagepump.h | 2 +- plugins/gtkui/gtkui.c | 12 ++++++------ 5 files changed, 20 insertions(+), 10 deletions(-) diff --git a/deadbeef.h b/deadbeef.h index 4c4d0f88..209911b8 100644 --- a/deadbeef.h +++ b/deadbeef.h @@ -218,7 +218,6 @@ typedef int (*DB_callback_t)(DB_event_t *, uintptr_t data); // events enum { - DB_EV_FRAMEUPDATE = 0, // ticks around 20 times per second, but ticker may stop sometimes DB_EV_SONGCHANGED = 1, // triggers when song was just changed DB_EV_SONGSTARTED = 2, // triggers when song started playing (for scrobblers and such) DB_EV_SONGFINISHED = 3, // triggers when song finished playing (for scrobblers and such) diff --git a/main.c b/main.c index 636542ac..d61b772f 100644 --- a/main.c +++ b/main.c @@ -389,6 +389,7 @@ player_mainloop (void) { uintptr_t ctx; uint32_t p1; uint32_t p2; + messagepump_wait (); while (messagepump_pop(&msg, &ctx, &p1, &p2) != -1) { DB_output_t *output = plug_get_output (); switch (msg) { @@ -455,8 +456,8 @@ player_mainloop (void) { break; } } - usleep(50000); - plug_trigger_event (DB_EV_FRAMEUPDATE, 0); + //usleep(50000); + //plug_trigger_event (DB_EV_FRAMEUPDATE, 0); } } diff --git a/messagepump.c b/messagepump.c index 368f0739..931b67db 100644 --- a/messagepump.c +++ b/messagepump.c @@ -34,6 +34,7 @@ static message_t *mfree; static message_t *mqueue; static message_t *mqtail; static uintptr_t mutex; +static uintptr_t cond; static void messagepump_reset (void); @@ -42,6 +43,7 @@ int messagepump_init (void) { messagepump_reset (); mutex = mutex_create (); + cond = cond_create (); return 0; } @@ -51,6 +53,7 @@ messagepump_free () { messagepump_reset (); mutex_unlock (mutex); mutex_free (mutex); + cond_free (cond); } static void @@ -88,9 +91,16 @@ messagepump_push (uint32_t id, uintptr_t ctx, uint32_t p1, uint32_t p2) { msg->p1 = p1; msg->p2 = p2; mutex_unlock (mutex); + cond_signal (cond); return 0; } +void +messagepump_wait (void) { + cond_wait (cond, mutex); + mutex_unlock (mutex); +} + int messagepump_pop (uint32_t *id, uintptr_t *ctx, uint32_t *p1, uint32_t *p2) { if (!mqueue) { diff --git a/messagepump.h b/messagepump.h index ec5a18a4..b22da711 100644 --- a/messagepump.h +++ b/messagepump.h @@ -24,6 +24,6 @@ int messagepump_init (void); void messagepump_free (void); int messagepump_push (uint32_t id, uintptr_t ctx, uint32_t p1, uint32_t p2); int messagepump_pop (uint32_t *id, uintptr_t *ctx, uint32_t *p1, uint32_t *p2); -//int messagepump_hasmessages (void); +void messagepump_wait (void); #endif // __MESSAGEPUMP_H diff --git a/plugins/gtkui/gtkui.c b/plugins/gtkui/gtkui.c index fb2c157b..f27f1ecb 100644 --- a/plugins/gtkui/gtkui.c +++ b/plugins/gtkui/gtkui.c @@ -531,11 +531,11 @@ gtkui_on_playlistswitch (DB_event_t *ev, uintptr_t data) { return 0; } -static int -gtkui_on_frameupdate (DB_event_t *ev, uintptr_t data) { - g_idle_add (update_songinfo, NULL); +static gboolean +gtkui_on_frameupdate (uintptr_t data) { + update_songinfo (NULL); - return 0; + return TRUE; } static gboolean @@ -1037,12 +1037,13 @@ gtkui_thread (void *ctx) { deadbeef->ev_subscribe (DB_PLUGIN (&plugin), DB_EV_TRACKINFOCHANGED, DB_CALLBACK (gtkui_on_trackinfochanged), 0); deadbeef->ev_subscribe (DB_PLUGIN (&plugin), DB_EV_PAUSED, DB_CALLBACK (gtkui_on_paused), 0); deadbeef->ev_subscribe (DB_PLUGIN (&plugin), DB_EV_PLAYLISTCHANGED, DB_CALLBACK (gtkui_on_playlistchanged), 0); - deadbeef->ev_subscribe (DB_PLUGIN (&plugin), DB_EV_FRAMEUPDATE, DB_CALLBACK (gtkui_on_frameupdate), 0); deadbeef->ev_subscribe (DB_PLUGIN (&plugin), DB_EV_VOLUMECHANGED, DB_CALLBACK (gtkui_on_volumechanged), 0); deadbeef->ev_subscribe (DB_PLUGIN (&plugin), DB_EV_CONFIGCHANGED, DB_CALLBACK (gtkui_on_configchanged), 0); deadbeef->ev_subscribe (DB_PLUGIN (&plugin), DB_EV_OUTPUTCHANGED, DB_CALLBACK (gtkui_on_outputchanged), 0); deadbeef->ev_subscribe (DB_PLUGIN (&plugin), DB_EV_PLAYLISTSWITCH, DB_CALLBACK (gtkui_on_playlistswitch), 0); + g_timeout_add (100, gtkui_on_frameupdate, NULL); + char str[600]; deadbeef->pl_format_title (NULL, -1, str, sizeof (str), -1, deadbeef->conf_get_str ("gtkui.titlebar_stopped", "DeaDBeeF-%V")); gtk_window_set_title (GTK_WINDOW (mainwin), str); @@ -1233,7 +1234,6 @@ gtkui_stop (void) { deadbeef->ev_unsubscribe (DB_PLUGIN (&plugin), DB_EV_TRACKINFOCHANGED, DB_CALLBACK (gtkui_on_trackinfochanged), 0); deadbeef->ev_unsubscribe (DB_PLUGIN (&plugin), DB_EV_PAUSED, DB_CALLBACK (gtkui_on_paused), 0); deadbeef->ev_unsubscribe (DB_PLUGIN (&plugin), DB_EV_PLAYLISTCHANGED, DB_CALLBACK (gtkui_on_playlistchanged), 0); - deadbeef->ev_unsubscribe (DB_PLUGIN (&plugin), DB_EV_FRAMEUPDATE, DB_CALLBACK (gtkui_on_frameupdate), 0); deadbeef->ev_unsubscribe (DB_PLUGIN (&plugin), DB_EV_VOLUMECHANGED, DB_CALLBACK (gtkui_on_volumechanged), 0); deadbeef->ev_unsubscribe (DB_PLUGIN (&plugin), DB_EV_CONFIGCHANGED, DB_CALLBACK (gtkui_on_configchanged), 0); deadbeef->ev_unsubscribe (DB_PLUGIN (&plugin), DB_EV_OUTPUTCHANGED, DB_CALLBACK (gtkui_on_outputchanged), 0); -- cgit v1.2.3