aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2013-02-27 20:28:19 +0100
committerMax Kellermann <max@duempel.org>2013-02-27 20:41:17 +0100
commit6f2e1c24151cd3734bd51673c5d2968e2c8bc1ae (patch)
tree61754bc3e78bedc7b2738436ff1fa6e7758335aa
parentfc0ad8674be2dfeef3e8e2fb8311f68da6243631 (diff)
GlobalEvents: use g_idle_add() instead of WakeFD()
Use the GMainLoop specific function to wake up the main loop. This is simpler and comes with very little overhead.
-rw-r--r--src/GlobalEvents.cxx33
1 files changed, 5 insertions, 28 deletions
diff --git a/src/GlobalEvents.cxx b/src/GlobalEvents.cxx
index 202df39b..20faa9a8 100644
--- a/src/GlobalEvents.cxx
+++ b/src/GlobalEvents.cxx
@@ -19,21 +19,16 @@
#include "config.h"
#include "GlobalEvents.hxx"
-#include "event/WakeFD.hxx"
-#include "mpd_error.h"
#include <atomic>
#include <assert.h>
#include <glib.h>
-#include <string.h>
-#include <errno.h>
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "global_events"
namespace GlobalEvents {
- static WakeFD wake_fd;
static guint source_id;
static std::atomic_uint flags;
static Handler handlers[MAX];
@@ -52,13 +47,8 @@ InvokeGlobalEvent(GlobalEvents::Event event)
}
static gboolean
-GlobalEventCallback(G_GNUC_UNUSED GIOChannel *source,
- G_GNUC_UNUSED GIOCondition condition,
- G_GNUC_UNUSED gpointer data)
+GlobalEventCallback(G_GNUC_UNUSED gpointer data)
{
- if (!GlobalEvents::wake_fd.Read())
- return true;
-
const unsigned flags = GlobalEvents::flags.exchange(0);
for (unsigned i = 0; i < GlobalEvents::MAX; ++i)
@@ -66,32 +56,19 @@ GlobalEventCallback(G_GNUC_UNUSED GIOChannel *source,
/* invoke the event handler */
InvokeGlobalEvent(GlobalEvents::Event(i));
- return true;
+ return false;
}
void
GlobalEvents::Initialize()
{
- if (!wake_fd.Create())
- MPD_ERROR("Couldn't open pipe: %s", strerror(errno));
-
-#ifndef G_OS_WIN32
- GIOChannel *channel = g_io_channel_unix_new(wake_fd.Get());
-#else
- GIOChannel *channel = g_io_channel_win32_new_socket(wake_fd.Get());
-#endif
-
- source_id = g_io_add_watch(channel, G_IO_IN,
- GlobalEventCallback, NULL);
- g_io_channel_unref(channel);
}
void
GlobalEvents::Deinitialize()
{
- g_source_remove(source_id);
-
- wake_fd.Destroy();
+ if (source_id != 0)
+ g_source_remove(source_id);
}
void
@@ -110,5 +87,5 @@ GlobalEvents::Emit(Event event)
const unsigned mask = 1u << unsigned(event);
if (GlobalEvents::flags.fetch_or(mask) == 0)
- wake_fd.Write();
+ source_id = g_idle_add(GlobalEventCallback, nullptr);
}