diff options
author | Max Kellermann <max@duempel.org> | 2013-08-07 22:16:59 +0200 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2013-08-10 13:54:23 +0200 |
commit | c1f4f1fdb64d97b5c3461723a8482ca64efea30e (patch) | |
tree | 54c8a9c1466beec0dbfac1c0b5f5773060c1aa2b /src/event/Call.cxx | |
parent | 342333f72a484e9f394026666c4b20e54dc9b756 (diff) | |
download | mpd-c1f4f1fdb64d97b5c3461723a8482ca64efea30e.tar.gz mpd-c1f4f1fdb64d97b5c3461723a8482ca64efea30e.tar.xz mpd-c1f4f1fdb64d97b5c3461723a8482ca64efea30e.zip |
EventLoop: new implementation using epoll
Implement an event loop without GLib.
Diffstat (limited to '')
-rw-r--r-- | src/event/Call.cxx | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/src/event/Call.cxx b/src/event/Call.cxx index c9f619472..e7d963ac3 100644 --- a/src/event/Call.cxx +++ b/src/event/Call.cxx @@ -27,7 +27,11 @@ #include <assert.h> -class BlockingCallMonitor final : DeferredMonitor { +class BlockingCallMonitor final +#ifndef USE_EPOLL + : DeferredMonitor +#endif +{ const std::function<void()> f; Mutex mutex; @@ -36,13 +40,24 @@ class BlockingCallMonitor final : DeferredMonitor { bool done; public: +#ifdef USE_EPOLL + BlockingCallMonitor(EventLoop &loop, std::function<void()> &&_f) + :f(std::move(_f)), done(false) { + loop.AddCall([this](){ + this->DoRun(); + }); + } +#else BlockingCallMonitor(EventLoop &_loop, std::function<void()> &&_f) :DeferredMonitor(_loop), f(std::move(_f)), done(false) {} +#endif void Run() { +#ifndef USE_EPOLL assert(!done); Schedule(); +#endif mutex.lock(); while (!done) @@ -50,8 +65,18 @@ public: mutex.unlock(); } +#ifndef USE_EPOLL private: virtual void RunDeferred() override { + DoRun(); + } + +#else +public: +#endif + void DoRun() { + assert(!done); + f(); mutex.lock(); |