Permalink
Browse files

Common: Use GCD semaphores on macOS

Unnamed semaphores are not supported.
  • Loading branch information...
stenzek committed May 31, 2018
1 parent a1b9a9f commit 041b977523e203c26c139ae4bdfa31a113072cd0
Showing with 25 additions and 1 deletion.
  1. +25 −1 Source/Core/Common/Semaphore.h
@@ -30,7 +30,31 @@ class Semaphore
};
} // namespace Common
#else // _WIN32
#elif defined(__APPLE__)
#include <dispatch/dispatch.h>
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 <semaphore.h>

0 comments on commit 041b977

Please sign in to comment.