Commit ce68701c authored by Max Kellermann's avatar Max Kellermann

event/Loop: add flag "dead"

parent 6ea2cb36
......@@ -25,7 +25,9 @@
#include "util/ScopeExit.hxx"
EventLoop::EventLoop(ThreadId _thread)
:SocketMonitor(*this), quit(false), thread(_thread)
:SocketMonitor(*this),
quit(false), dead(false),
thread(_thread)
{
SocketMonitor::Open(SocketDescriptor(wake_fd.Get()));
}
......@@ -142,10 +144,14 @@ EventLoop::Run() noexcept
assert(IsInside());
assert(!quit);
assert(!dead);
assert(busy);
SocketMonitor::Schedule(SocketMonitor::READ);
AtScopeExit(this) { SocketMonitor::Cancel(); };
AtScopeExit(this) {
dead = true;
SocketMonitor::Cancel();
};
do {
now = std::chrono::steady_clock::now();
......@@ -210,6 +216,7 @@ EventLoop::Run() noexcept
} while (!quit);
#ifndef NDEBUG
assert(!dead);
assert(busy);
assert(thread.IsInside());
#endif
......
......@@ -89,6 +89,11 @@ class EventLoop final : SocketMonitor
std::atomic_bool quit;
/**
* If this is true, then Run() has returned.
*/
std::atomic_bool dead;
/**
* True when the object has been modified and another check is
* necessary before going to sleep via PollGroup::ReadEvents().
*/
......@@ -199,6 +204,10 @@ private:
bool OnSocketReady(unsigned flags) noexcept override;
public:
gcc_pure
bool IsDead() const noexcept {
return dead;
}
/**
* Are we currently running inside this EventLoop's thread?
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment