From 0e7c4d3db479f9c3e33d6b8d645b892ab20ab987 Mon Sep 17 00:00:00 2001 From: Martin Ridgers Date: Fri, 26 Nov 2021 08:36:06 +0100 Subject: Clear out orphaned queues so they're initially unset --- zencore/thread.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'zencore/thread.cpp') 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); -- cgit v1.2.3