event/Loop: add flag "dead"
This commit is contained in:
parent
6ea2cb3644
commit
ce68701c0c
@ -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
|
|||||||
|
|
||||||
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
|
|||||||
} while (!quit);
|
} while (!quit);
|
||||||
|
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
|
assert(!dead);
|
||||||
assert(busy);
|
assert(busy);
|
||||||
assert(thread.IsInside());
|
assert(thread.IsInside());
|
||||||
#endif
|
#endif
|
||||||
|
@ -88,6 +88,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:
|
|||||||
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?
|
||||||
|
Loading…
Reference in New Issue
Block a user