From f685a4800899cd3f7812b303a2e12700bdc445e2 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Sun, 5 Jan 2014 01:32:59 +0100 Subject: [PATCH] event/Loop: move code to HandleDeferred() --- src/event/Loop.cxx | 20 ++++++++++++-------- src/event/Loop.hxx | 7 +++++++ 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/src/event/Loop.cxx b/src/event/Loop.cxx index 57c966bb7..8c8ac9993 100644 --- a/src/event/Loop.cxx +++ b/src/event/Loop.cxx @@ -217,15 +217,9 @@ EventLoop::RemoveDeferred(DeferredMonitor &d) deferred.erase(i); } -bool -EventLoop::OnSocketReady(gcc_unused unsigned flags) +void +EventLoop::HandleDeferred() { - assert(!quit); - - wake_fd.Read(); - - mutex.lock(); - while (!deferred.empty() && !quit) { DeferredMonitor &m = *deferred.front(); assert(m.pending); @@ -237,7 +231,17 @@ EventLoop::OnSocketReady(gcc_unused unsigned flags) m.RunDeferred(); mutex.lock(); } +} +bool +EventLoop::OnSocketReady(gcc_unused unsigned flags) +{ + assert(!quit); + + wake_fd.Read(); + + mutex.lock(); + HandleDeferred(); mutex.unlock(); return true; diff --git a/src/event/Loop.hxx b/src/event/Loop.hxx index 5ac7d635f..b8d090eb5 100644 --- a/src/event/Loop.hxx +++ b/src/event/Loop.hxx @@ -157,6 +157,13 @@ public: void Run(); private: + /** + * Invoke all pending DeferredMonitors. + * + * Caller must lock the mutex. + */ + void HandleDeferred(); + virtual bool OnSocketReady(unsigned flags) override; public: