Commit ce68701c authored by Max Kellermann's avatar Max Kellermann

event/Loop: add flag "dead"

parent 6ea2cb36
...@@ -25,7 +25,9 @@ ...@@ -25,7 +25,9 @@
#include "util/ScopeExit.hxx" #include "util/ScopeExit.hxx"
EventLoop::EventLoop(ThreadId _thread) EventLoop::EventLoop(ThreadId _thread)
:SocketMonitor(*this), quit(false), thread(_thread) :SocketMonitor(*this),
quit(false), dead(false),
thread(_thread)
{ {
SocketMonitor::Open(SocketDescriptor(wake_fd.Get())); SocketMonitor::Open(SocketDescriptor(wake_fd.Get()));
} }
...@@ -142,10 +144,14 @@ EventLoop::Run() noexcept ...@@ -142,10 +144,14 @@ EventLoop::Run() noexcept
assert(IsInside()); assert(IsInside());
assert(!quit); assert(!quit);
assert(!dead);
assert(busy); assert(busy);
SocketMonitor::Schedule(SocketMonitor::READ); SocketMonitor::Schedule(SocketMonitor::READ);
AtScopeExit(this) { SocketMonitor::Cancel(); }; AtScopeExit(this) {
dead = true;
SocketMonitor::Cancel();
};
do { do {
now = std::chrono::steady_clock::now(); now = std::chrono::steady_clock::now();
...@@ -210,6 +216,7 @@ EventLoop::Run() noexcept ...@@ -210,6 +216,7 @@ EventLoop::Run() noexcept
} while (!quit); } while (!quit);
#ifndef NDEBUG #ifndef NDEBUG
assert(!dead);
assert(busy); assert(busy);
assert(thread.IsInside()); assert(thread.IsInside());
#endif #endif
......
...@@ -89,6 +89,11 @@ class EventLoop final : SocketMonitor ...@@ -89,6 +89,11 @@ class EventLoop final : SocketMonitor
std::atomic_bool quit; 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 * True when the object has been modified and another check is
* necessary before going to sleep via PollGroup::ReadEvents(). * necessary before going to sleep via PollGroup::ReadEvents().
*/ */
...@@ -199,6 +204,10 @@ private: ...@@ -199,6 +204,10 @@ private:
bool OnSocketReady(unsigned flags) noexcept override; bool OnSocketReady(unsigned flags) noexcept override;
public: public:
gcc_pure
bool IsDead() const noexcept {
return dead;
}
/** /**
* Are we currently running inside this EventLoop's thread? * 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