event/Loop: add flag alive

This replaces the old `dead` flag which was unreliable; it was `false`
if the EventThread was not yet started, which could cause deadlocks in
BlockingCall().
This commit is contained in:
Max Kellermann
2019-02-05 22:38:45 +01:00
parent 261a816b21
commit 6c67408944
4 changed files with 28 additions and 12 deletions

View File

@@ -26,8 +26,11 @@
void
EventThread::Start()
{
assert(!event_loop.IsAlive());
assert(!thread.IsDefined());
event_loop.SetAlive(true);
thread.Start();
}
@@ -35,6 +38,9 @@ void
EventThread::Stop() noexcept
{
if (thread.IsDefined()) {
assert(event_loop.IsAlive());
event_loop.SetAlive(false);
event_loop.Break();
thread.Join();
}