diff options
author | Denis Krjuchkov <denis@crazydev.net> | 2013-11-27 17:04:38 +0600 |
---|---|---|
committer | Denis Krjuchkov <denis@crazydev.net> | 2013-11-27 17:28:36 +0600 |
commit | 46bab7e4b921b79924643bacd08dcd3d1404ceb6 (patch) | |
tree | 2fe8e1b2185dba89d953b5d02f22cc0781e17c2c /src/event/DeferredMonitor.hxx | |
parent | 22fb49fa90241abfaf5ac81de462f4b2c274f7d0 (diff) | |
download | mpd-46bab7e4b921b79924643bacd08dcd3d1404ceb6.tar.gz mpd-46bab7e4b921b79924643bacd08dcd3d1404ceb6.tar.xz mpd-46bab7e4b921b79924643bacd08dcd3d1404ceb6.zip |
Add infrastructure for using multiple event loops
This change adds two configuration options:
--with-eventloop=[glib|internal|auto]
--with-pollmethod=[epoll|auto]
First allows switching between GLib event loop and internal one.
Second chooses backend to use for internal event loop.
Conditional compilation symbols are changed accordingly.
Additional helper macro MPD_OPTIONAL_FUNC_NODEF is added as well.
Diffstat (limited to '')
-rw-r--r-- | src/event/DeferredMonitor.hxx | 39 |
1 files changed, 25 insertions, 14 deletions
diff --git a/src/event/DeferredMonitor.hxx b/src/event/DeferredMonitor.hxx index 2380fb66f..d4c812e44 100644 --- a/src/event/DeferredMonitor.hxx +++ b/src/event/DeferredMonitor.hxx @@ -23,10 +23,12 @@ #include "check.h" #include "Compiler.h" -#ifdef USE_EPOLL +#ifdef USE_INTERNAL_EVENTLOOP #include "SocketMonitor.hxx" #include "WakeFD.hxx" -#else +#endif + +#ifdef USE_GLIB_EVENTLOOP #include <glib.h> #endif @@ -38,44 +40,51 @@ class EventLoop; * Defer execution of an event into an #EventLoop. */ class DeferredMonitor -#ifdef USE_EPOLL +#ifdef USE_INTERNAL_EVENTLOOP : private SocketMonitor #endif { -#ifdef USE_EPOLL +#ifdef USE_INTERNAL_EVENTLOOP std::atomic_bool pending; WakeFD fd; -#else - EventLoop &loop; +#endif +#ifdef USE_GLIB_EVENTLOOP + EventLoop &loop; std::atomic<guint> source_id; #endif public: -#ifdef USE_EPOLL +#ifdef USE_INTERNAL_EVENTLOOP DeferredMonitor(EventLoop &_loop) :SocketMonitor(_loop), pending(false) { SocketMonitor::Open(fd.Get()); SocketMonitor::Schedule(SocketMonitor::READ); } -#else +#endif + +#ifdef USE_GLIB_EVENTLOOP DeferredMonitor(EventLoop &_loop) :loop(_loop), source_id(0) {} #endif ~DeferredMonitor() { -#ifdef USE_EPOLL +#ifdef USE_INTERNAL_EVENTLOOP /* avoid closing the WakeFD twice */ SocketMonitor::Steal(); -#else +#endif + +#ifdef USE_GLIB_EVENTLOOP Cancel(); #endif } EventLoop &GetEventLoop() { -#ifdef USE_EPOLL +#ifdef USE_INTERNAL_EVENTLOOP return SocketMonitor::GetEventLoop(); -#else +#endif + +#ifdef USE_GLIB_EVENTLOOP return loop; #endif } @@ -87,9 +96,11 @@ protected: virtual void RunDeferred() = 0; private: -#ifdef USE_EPOLL +#ifdef USE_INTERNAL_EVENTLOOP virtual bool OnSocketReady(unsigned flags) override final; -#else +#endif + +#ifdef USE_GLIB_EVENTLOOP void Run(); static gboolean Callback(gpointer data); #endif |