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

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