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.
This commit is contained in:
Denis Krjuchkov
2013-11-27 17:04:38 +06:00
parent 22fb49fa90
commit 46bab7e4b9
15 changed files with 295 additions and 114 deletions

View File

@@ -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)