event/Loop: move code to HandleDeferred()

This commit is contained in:
Max Kellermann 2014-01-05 01:32:59 +01:00
parent 7c15e41da5
commit f685a48008
2 changed files with 19 additions and 8 deletions

View File

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

View File

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