From 2b946b4668323d9ff6eb971c288e89cf11209d69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Branimir=20Karad=C5=BEi=C4=87?= Date: Tue, 24 Feb 2026 19:37:50 -0800 Subject: [PATCH] Apple: Allow semaphore to process block events. (#369) --- src/semaphore.cpp | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/src/semaphore.cpp b/src/semaphore.cpp index dd02bac..ecdc5ea 100644 --- a/src/semaphore.cpp +++ b/src/semaphore.cpp @@ -11,7 +11,7 @@ #elif BX_PLATFORM_OSX \ || BX_PLATFORM_IOS \ || BX_PLATFORM_VISIONOS -# include +# include #elif BX_PLATFORM_POSIX # include # include @@ -104,10 +104,31 @@ namespace bx { SemaphoreInternal* si = (SemaphoreInternal*)m_internal; - dispatch_time_t dt = 0 > _msecs - ? DISPATCH_TIME_FOREVER - : dispatch_time(DISPATCH_TIME_NOW, int64_t(_msecs)*1000000) - ; + static constexpr int64_t kNanosecondsInMilisecond = 1000000; + + if (0 > _msecs) + { + while (true) + { + const dispatch_time_t dt = dispatch_time( + DISPATCH_TIME_NOW + , 300*kNanosecondsInMilisecond + ); + if (0 == dispatch_semaphore_wait(si->m_handle, dt) ) + { + return true; + } + + CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0, true); + } + + BX_UNREACHABLE; + } + + const dispatch_time_t dt = dispatch_time( + DISPATCH_TIME_NOW + , int64_t(_msecs)*kNanosecondsInMilisecond + ); return !dispatch_semaphore_wait(si->m_handle, dt); }