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/Loop.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 'src/event/Loop.hxx')
-rw-r--r-- | src/event/Loop.hxx | 33 |
1 files changed, 24 insertions, 9 deletions
diff --git a/src/event/Loop.hxx b/src/event/Loop.hxx index 223527853..f188c7cc0 100644 --- a/src/event/Loop.hxx +++ b/src/event/Loop.hxx @@ -24,8 +24,11 @@ #include "thread/Id.hxx" #include "Compiler.h" +#ifdef USE_INTERNAL_EVENTLOOP #ifdef USE_EPOLL #include "system/EPollFD.hxx" +#endif + #include "thread/Mutex.hxx" #include "WakeFD.hxx" #include "SocketMonitor.hxx" @@ -33,11 +36,13 @@ #include <functional> #include <list> #include <set> -#else +#endif + +#ifdef USE_GLIB_EVENTLOOP #include <glib.h> #endif -#ifdef USE_EPOLL +#ifdef USE_INTERNAL_EVENTLOOP class TimeoutMonitor; class IdleMonitor; class SocketMonitor; @@ -55,11 +60,11 @@ class SocketMonitor; * @see SocketMonitor, MultiSocketMonitor, TimeoutMonitor, IdleMonitor */ class EventLoop final -#ifdef USE_EPOLL +#ifdef USE_INTERNAL_EVENTLOOP : private SocketMonitor #endif { -#ifdef USE_EPOLL +#ifdef USE_INTERNAL_EVENTLOOP struct TimerRecord { /** * Projected monotonic_clock_ms() value when this @@ -82,8 +87,6 @@ class EventLoop final } }; - EPollFD epoll; - WakeFD wake_fd; std::multiset<TimerRecord> timers; @@ -96,10 +99,16 @@ class EventLoop final bool quit; +#ifdef USE_EPOLL + EPollFD epoll; static constexpr unsigned MAX_EVENTS = 16; unsigned n_events; epoll_event events[MAX_EVENTS]; -#else +#endif + +#endif + +#ifdef USE_GLIB_EVENTLOOP GMainContext *context; GMainLoop *loop; #endif @@ -110,7 +119,7 @@ class EventLoop final ThreadId thread; public: -#ifdef USE_EPOLL +#ifdef USE_INTERNAL_EVENTLOOP struct Default {}; EventLoop(Default dummy=Default()); @@ -131,11 +140,15 @@ public: void Break(); bool AddFD(int _fd, unsigned flags, SocketMonitor &m) { +#ifdef USE_EPOLL return epoll.Add(_fd, flags, &m); +#endif } bool ModifyFD(int _fd, unsigned flags, SocketMonitor &m) { +#ifdef USE_EPOLL return epoll.Modify(_fd, flags, &m); +#endif } /** @@ -165,7 +178,9 @@ private: virtual bool OnSocketReady(unsigned flags) override; public: -#else +#endif + +#ifdef USE_GLIB_EVENTLOOP EventLoop() :context(g_main_context_new()), loop(g_main_loop_new(context, false)), |