aboutsummaryrefslogtreecommitdiff
path: root/zencore/thread.cpp
diff options
context:
space:
mode:
authorMartin Ridgers <[email protected]>2021-11-26 08:36:06 +0100
committerMartin Ridgers <[email protected]>2021-11-26 08:36:06 +0100
commit0e7c4d3db479f9c3e33d6b8d645b892ab20ab987 (patch)
treed0b0c99314346cc28d1e4a6d5f276e3e385530ed /zencore/thread.cpp
parentAllow end-of-file errors to pass unraised (diff)
downloadzen-0e7c4d3db479f9c3e33d6b8d645b892ab20ab987.tar.xz
zen-0e7c4d3db479f9c3e33d6b8d645b892ab20ab987.zip
Clear out orphaned queues so they're initially unset
Diffstat (limited to 'zencore/thread.cpp')
-rw-r--r--zencore/thread.cpp10
1 files changed, 8 insertions, 2 deletions
diff --git a/zencore/thread.cpp b/zencore/thread.cpp
index 981d2bd96..ee62b5248 100644
--- a/zencore/thread.cpp
+++ b/zencore/thread.cpp
@@ -278,8 +278,14 @@ NamedEvent::NamedEvent(std::string_view EventName)
int LockResult = flock(Inner, LOCK_EX|LOCK_NB);
if (LockResult == 0)
{
- ZEN_ASSERT( IsMessageQueueEmpty(Inner),
- "Ownership of a non-empty '{}' message queue occurred", Name.c_str());
+ // This is really thread safe as the message queue could be set between
+ // getting the exclusive lock and checking the queue. But for the our
+ // simple synchronising of process, this should be okay.
+ while (!IsMessageQueueEmpty(Inner))
+ {
+ char Sink;
+ mq_receive(Inner, &Sink, sizeof(Sink), nullptr);
+ }
}
m_EventHandle = (void*)intptr_t(Inner);