diff options
Diffstat (limited to '')
-rw-r--r-- | src/GlobalEvents.cxx | 7 | ||||
-rw-r--r-- | src/GlobalEvents.hxx | 4 | ||||
-rw-r--r-- | src/Main.cxx | 2 | ||||
-rw-r--r-- | src/event/DeferredMonitor.cxx | 2 | ||||
-rw-r--r-- | src/event/DeferredMonitor.hxx | 8 |
5 files changed, 16 insertions, 7 deletions
diff --git a/src/GlobalEvents.cxx b/src/GlobalEvents.cxx index ade745535..ed7697b1a 100644 --- a/src/GlobalEvents.cxx +++ b/src/GlobalEvents.cxx @@ -33,6 +33,9 @@ namespace GlobalEvents { class Monitor final : public DeferredMonitor { + public: + Monitor(EventLoop &_loop):DeferredMonitor(_loop) {} + protected: virtual void Run() override; }; @@ -67,9 +70,9 @@ GlobalEvents::Monitor::Run() } void -GlobalEvents::Initialize() +GlobalEvents::Initialize(EventLoop &loop) { - monitor.Construct(); + monitor.Construct(loop); } void diff --git a/src/GlobalEvents.hxx b/src/GlobalEvents.hxx index 16de7e675..47ec6d070 100644 --- a/src/GlobalEvents.hxx +++ b/src/GlobalEvents.hxx @@ -29,6 +29,8 @@ #endif #endif +class EventLoop; + namespace GlobalEvents { enum Event { /** database update was finished */ @@ -59,7 +61,7 @@ namespace GlobalEvents { typedef void (*Handler)(); - void Initialize(); + void Initialize(EventLoop &loop); void Deinitialize(); diff --git a/src/Main.cxx b/src/Main.cxx index a1a3fe976..42403922c 100644 --- a/src/Main.cxx +++ b/src/Main.cxx @@ -438,7 +438,7 @@ int mpd_main(int argc, char *argv[]) daemonize_set_user(); - GlobalEvents::Initialize(); + GlobalEvents::Initialize(*main_loop); GlobalEvents::Register(GlobalEvents::IDLE, idle_event_emitted); #ifdef WIN32 GlobalEvents::Register(GlobalEvents::SHUTDOWN, shutdown_event_emitted); diff --git a/src/event/DeferredMonitor.cxx b/src/event/DeferredMonitor.cxx index 10aa0d757..e4242414c 100644 --- a/src/event/DeferredMonitor.cxx +++ b/src/event/DeferredMonitor.cxx @@ -32,7 +32,7 @@ DeferredMonitor::Cancel() void DeferredMonitor::Schedule() { - const unsigned id = g_idle_add(Callback, this); + const unsigned id = loop.AddIdle(Callback, this); const auto old_id = source_id.exchange(id); if (old_id != 0) g_source_remove(old_id); diff --git a/src/event/DeferredMonitor.hxx b/src/event/DeferredMonitor.hxx index 8a08facba..e055b6c9d 100644 --- a/src/event/DeferredMonitor.hxx +++ b/src/event/DeferredMonitor.hxx @@ -26,15 +26,19 @@ #include <atomic> +class EventLoop; + /** * Defer execution of an event into an #EventLoop. */ class DeferredMonitor { + EventLoop &loop; + std::atomic<guint> source_id; public: - DeferredMonitor() - :source_id(0) {} + DeferredMonitor(EventLoop &_loop) + :loop(_loop), source_id(0) {} ~DeferredMonitor() { Cancel(); |