summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMax Kellermann <max@musicpd.org>2018-01-29 22:52:13 +0100
committerMax Kellermann <max@musicpd.org>2018-01-29 22:52:13 +0100
commitce68701c0cc8b55ef500a409320fa13d126e1b3f (patch)
tree203ae40508b5ba6e841ec5683557d7351359bab7 /src
parent6ea2cb3644c7915ab1262384edc4da5ff4917ca0 (diff)
event/Loop: add flag "dead"
Diffstat (limited to 'src')
-rw-r--r--src/event/Loop.cxx11
-rw-r--r--src/event/Loop.hxx9
2 files changed, 18 insertions, 2 deletions
diff --git a/src/event/Loop.cxx b/src/event/Loop.cxx
index a52921084..a80463869 100644
--- a/src/event/Loop.cxx
+++ b/src/event/Loop.cxx
@@ -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
diff --git a/src/event/Loop.hxx b/src/event/Loop.hxx
index 788933f03..f578243d5 100644
--- a/src/event/Loop.hxx
+++ b/src/event/Loop.hxx
@@ -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?