aboutsummaryrefslogtreecommitdiffstats
path: root/src/GlobalEvents.cxx
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2013-08-07 18:59:42 +0200
committerMax Kellermann <max@duempel.org>2013-08-07 18:59:42 +0200
commit355dd5cb24f1d36cb13a2463ce7585186474adc8 (patch)
treec70eab6b1c8d51820817a2bad92b877415985c4c /src/GlobalEvents.cxx
parent123dd5fe2de35f881a17779e3aca4cd48195610f (diff)
downloadmpd-355dd5cb24f1d36cb13a2463ce7585186474adc8.tar.gz
mpd-355dd5cb24f1d36cb13a2463ce7585186474adc8.tar.xz
mpd-355dd5cb24f1d36cb13a2463ce7585186474adc8.zip
event/DeferredMonitor: new class wrapping g_idle_add()
Diffstat (limited to 'src/GlobalEvents.cxx')
-rw-r--r--src/GlobalEvents.cxx30
1 files changed, 18 insertions, 12 deletions
diff --git a/src/GlobalEvents.cxx b/src/GlobalEvents.cxx
index e30090ef4..ade745535 100644
--- a/src/GlobalEvents.cxx
+++ b/src/GlobalEvents.cxx
@@ -19,6 +19,8 @@
#include "config.h"
#include "GlobalEvents.hxx"
+#include "util/Manual.hxx"
+#include "event/DeferredMonitor.hxx"
#include "gcc.h"
#include <atomic>
@@ -30,7 +32,13 @@
#define G_LOG_DOMAIN "global_events"
namespace GlobalEvents {
- static guint source_id;
+ class Monitor final : public DeferredMonitor {
+ protected:
+ virtual void Run() override;
+ };
+
+ static Manual<Monitor> monitor;
+
static std::atomic_uint flags;
static Handler handlers[MAX];
}
@@ -47,29 +55,27 @@ InvokeGlobalEvent(GlobalEvents::Event event)
GlobalEvents::handlers[event]();
}
-static gboolean
-GlobalEventCallback(gcc_unused gpointer data)
+void
+GlobalEvents::Monitor::Run()
{
- const unsigned flags = GlobalEvents::flags.exchange(0);
+ const unsigned f = flags.exchange(0);
- for (unsigned i = 0; i < GlobalEvents::MAX; ++i)
- if (flags & (1u << i))
+ for (unsigned i = 0; i < MAX; ++i)
+ if (f & (1u << i))
/* invoke the event handler */
- InvokeGlobalEvent(GlobalEvents::Event(i));
-
- return false;
+ InvokeGlobalEvent(Event(i));
}
void
GlobalEvents::Initialize()
{
+ monitor.Construct();
}
void
GlobalEvents::Deinitialize()
{
- if (source_id != 0)
- g_source_remove(source_id);
+ monitor.Destruct();
}
void
@@ -88,5 +94,5 @@ GlobalEvents::Emit(Event event)
const unsigned mask = 1u << unsigned(event);
if (GlobalEvents::flags.fetch_or(mask) == 0)
- source_id = g_idle_add(GlobalEventCallback, nullptr);
+ monitor->Schedule();
}