Use separate 32-bit second and nanosecond atomics for the clock
[openal-soft.git] / common / alsem.h
blob90b3931902651f7bc42f15771d6e22b96d48f384
1 #ifndef COMMON_ALSEM_H
2 #define COMMON_ALSEM_H
4 #if defined(__APPLE__)
5 #include <AvailabilityMacros.h>
6 #include <TargetConditionals.h>
7 #if (((MAC_OS_X_VERSION_MIN_REQUIRED > 1050) && !defined(__ppc__)) || TARGET_OS_IOS || TARGET_OS_TV)
8 #include <dispatch/dispatch.h>
9 #define AL_APPLE_HAVE_DISPATCH 1
10 #else
11 #include <semaphore.h> /* Fallback option for Apple without a working libdispatch */
12 #endif
13 #elif !defined(_WIN32)
14 #include <semaphore.h>
15 #endif
17 namespace al {
19 class semaphore {
20 #ifdef _WIN32
21 using native_type = void*;
22 #elif defined(AL_APPLE_HAVE_DISPATCH)
23 using native_type = dispatch_semaphore_t;
24 #else
25 using native_type = sem_t;
26 #endif
27 native_type mSem{};
29 public:
30 semaphore(unsigned int initial=0);
31 semaphore(const semaphore&) = delete;
32 ~semaphore();
34 semaphore& operator=(const semaphore&) = delete;
36 void post();
37 void wait() noexcept;
38 bool try_wait() noexcept;
41 } // namespace al
43 #endif /* COMMON_ALSEM_H */