aboutsummaryrefslogtreecommitdiffstats
path: root/src/event/Loop.cxx
diff options
context:
space:
mode:
authorDenis Krjuchkov <denis@crazydev.net>2013-11-27 17:04:38 +0600
committerDenis Krjuchkov <denis@crazydev.net>2013-11-27 17:28:36 +0600
commit46bab7e4b921b79924643bacd08dcd3d1404ceb6 (patch)
tree2fe8e1b2185dba89d953b5d02f22cc0781e17c2c /src/event/Loop.cxx
parent22fb49fa90241abfaf5ac81de462f4b2c274f7d0 (diff)
downloadmpd-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/Loop.cxx23
1 files changed, 18 insertions, 5 deletions
diff --git a/src/event/Loop.cxx b/src/event/Loop.cxx
index 5aa24aea2..ccba7bb45 100644
--- a/src/event/Loop.cxx
+++ b/src/event/Loop.cxx
@@ -20,7 +20,7 @@
#include "config.h"
#include "Loop.hxx"
-#ifdef USE_EPOLL
+#ifdef USE_INTERNAL_EVENTLOOP
#include "system/Clock.hxx"
#include "TimeoutMonitor.hxx"
@@ -33,7 +33,9 @@ EventLoop::EventLoop(Default)
:SocketMonitor(*this),
now_ms(::MonotonicClockMS()),
quit(false),
+#ifdef USE_EPOLL
n_events(0),
+#endif
thread(ThreadId::Null())
{
SocketMonitor::Open(wake_fd.Get());
@@ -61,16 +63,20 @@ EventLoop::Break()
void
EventLoop::Abandon(SocketMonitor &m)
{
+#ifdef USE_EPOLL
for (unsigned i = 0, n = n_events; i < n; ++i)
if (events[i].data.ptr == &m)
events[i].events = 0;
+#endif
}
bool
EventLoop::RemoveFD(int _fd, SocketMonitor &m)
{
+#ifdef USE_EPOLL
Abandon(m);
return epoll.Remove(_fd);
+#endif
}
void
@@ -115,7 +121,7 @@ EventLoop::Run()
assert(thread.IsNull());
thread = ThreadId::GetCurrent();
-#ifdef USE_EPOLL
+#ifdef USE_INTERNAL_EVENTLOOP
assert(!quit);
do {
@@ -162,6 +168,7 @@ EventLoop::Run()
timeout */
continue;
+#ifdef USE_EPOLL
/* wait for new event */
const int n = epoll.Wait(events, MAX_EVENTS, timeout_ms);
@@ -186,15 +193,19 @@ EventLoop::Run()
}
n_events = 0;
+#endif
} while (!quit);
-#else
+
+#endif
+
+#ifdef USE_GLIB_EVENTLOOP
g_main_loop_run(loop);
#endif
assert(thread.IsInside());
}
-#ifdef USE_EPOLL
+#ifdef USE_INTERNAL_EVENTLOOP
void
EventLoop::AddCall(std::function<void()> &&f)
@@ -229,7 +240,9 @@ EventLoop::OnSocketReady(gcc_unused unsigned flags)
return true;
}
-#else
+#endif
+
+#ifdef USE_GLIB_EVENTLOOP
guint
EventLoop::AddIdle(GSourceFunc function, gpointer data)