diff options
author | Max Kellermann <max@duempel.org> | 2014-01-04 14:56:02 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2014-01-04 15:58:59 +0100 |
commit | a357d84dce668d126fe984680e5d17f6d41b2fe6 (patch) | |
tree | a85f021ed1d7f999592f5fb3878a4b723755d1cd /src/event/DeferredMonitor.cxx | |
parent | 48c96bbaea542491b930f244e22d17db5a281434 (diff) |
event/DeferredMonitor: make fully thread-safe
Instead of creating a new eventfd for each DeferredMonitor instance,
reuse EventLoop's eventfd, and add a std::list to EventLoop that
manages the list of pending DeferredMonitors. This std::list is
protected by the same mutex as the "calls" list.
The bottom line is: reduced overhead because the per-instance eventfd
was eliminated, slightly added overhead due to Mutex usage (but
negligible), and we're thread-safe now.
This subsystem is now good enough to replace EventLoop::AddCall().
Diffstat (limited to 'src/event/DeferredMonitor.cxx')
-rw-r--r-- | src/event/DeferredMonitor.cxx | 20 |
1 files changed, 2 insertions, 18 deletions
diff --git a/src/event/DeferredMonitor.cxx b/src/event/DeferredMonitor.cxx index 40b4b0b62..5f295946e 100644 --- a/src/event/DeferredMonitor.cxx +++ b/src/event/DeferredMonitor.cxx @@ -25,7 +25,7 @@ void DeferredMonitor::Cancel() { #ifdef USE_INTERNAL_EVENTLOOP - pending = false; + loop.RemoveDeferred(*this); #endif #ifdef USE_GLIB_EVENTLOOP const auto id = source_id.exchange(0); @@ -38,8 +38,7 @@ void DeferredMonitor::Schedule() { #ifdef USE_INTERNAL_EVENTLOOP - if (!pending.exchange(true)) - fd.Write(); + loop.AddDeferred(*this); #endif #ifdef USE_GLIB_EVENTLOOP const unsigned id = loop.AddIdle(Callback, this); @@ -49,21 +48,6 @@ DeferredMonitor::Schedule() #endif } -#ifdef USE_INTERNAL_EVENTLOOP - -bool -DeferredMonitor::OnSocketReady(unsigned) -{ - fd.Read(); - - if (pending.exchange(false)) - RunDeferred(); - - return true; -} - -#endif - #ifdef USE_GLIB_EVENTLOOP void |