From 041b977523e203c26c139ae4bdfa31a113072cd0 Mon Sep 17 00:00:00 2001 From: Stenzek Date: Thu, 31 May 2018 04:22:20 -0700 Subject: [PATCH] Common: Use GCD semaphores on macOS Unnamed semaphores are not supported. --- Source/Core/Common/Semaphore.h | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/Source/Core/Common/Semaphore.h b/Source/Core/Common/Semaphore.h index 0c48d2fb4d..d132288f2a 100644 --- a/Source/Core/Common/Semaphore.h +++ b/Source/Core/Common/Semaphore.h @@ -30,7 +30,31 @@ private: }; } // namespace Common -#else // _WIN32 +#elif defined(__APPLE__) + +#include + +namespace Common +{ +class Semaphore +{ +public: + Semaphore(int initial_count, int maximum_count) + { + m_handle = dispatch_semaphore_create(0); + for (int i = 0; i < initial_count; i++) + dispatch_semaphore_signal(m_handle); + } + ~Semaphore() { dispatch_release(m_handle); } + void Wait() { dispatch_semaphore_wait(m_handle, DISPATCH_TIME_FOREVER); } + void Post() { dispatch_semaphore_signal(m_handle); } + +private: + dispatch_semaphore_t m_handle; +}; +} // namespace Common + +#else #include