From a094fb8104271f8e02f0a72f52583e6c7f9ee1ea Mon Sep 17 00:00:00 2001 From: Geoffrey McRae Date: Sun, 1 Aug 2021 17:13:31 +1000 Subject: [PATCH] [common] events/linux: fix failure to call pthread_cond_broadcast --- common/src/platform/linux/event.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/common/src/platform/linux/event.c b/common/src/platform/linux/event.c index 762f2156..f0607f22 100644 --- a/common/src/platform/linux/event.c +++ b/common/src/platform/linux/event.c @@ -175,15 +175,25 @@ bool lgSignalEvent(LGEvent * handle) { assert(handle); + if (pthread_mutex_lock(&handle->mutex) != 0) + { + DEBUG_ERROR("Failed to lock the mutex"); + return false; + } + const bool signaled = atomic_exchange_explicit(&handle->signaled, true, memory_order_release); - if (signaled) - return true; + if (!signaled) + if (pthread_cond_broadcast(&handle->cond) != 0) + { + DEBUG_ERROR("Failed to signal the condition"); + return false; + } - if (pthread_cond_broadcast(&handle->cond) != 0) + if (pthread_mutex_unlock(&handle->mutex) != 0) { - DEBUG_ERROR("Failed to signal the condition"); + DEBUG_ERROR("Failed to unlock the mutex"); return false; }