Increase the priority of the ALSA backend
[openal-soft.git] / common / threads.h
blob1cdb5d8f6a9b1a7e5cfc95976f33a1ce1c299a3e
1 #ifndef AL_THREADS_H
2 #define AL_THREADS_H
4 #if defined(__GNUC__) && defined(__i386__)
5 /* force_align_arg_pointer is required for proper function arguments aligning
6 * when SSE code is used. Some systems (Windows, QNX) do not guarantee our
7 * thread functions will be properly aligned on the stack, even though GCC may
8 * generate code with the assumption that it is. */
9 #define FORCE_ALIGN __attribute__((force_align_arg_pointer))
10 #else
11 #define FORCE_ALIGN
12 #endif
14 #if defined(__APPLE__)
15 #include <dispatch/dispatch.h>
16 #elif !defined(_WIN32)
17 #include <semaphore.h>
18 #endif
20 void althrd_setname(const char *name);
22 namespace al {
24 class semaphore {
25 #ifdef _WIN32
26 using native_type = void*;
27 #elif defined(__APPLE__)
28 using native_type = dispatch_semaphore_t;
29 #else
30 using native_type = sem_t;
31 #endif
32 native_type mSem;
34 public:
35 semaphore(unsigned int initial=0);
36 semaphore(const semaphore&) = delete;
37 ~semaphore();
39 semaphore& operator=(const semaphore&) = delete;
41 void post();
42 void wait() noexcept;
43 bool try_wait() noexcept;
46 } // namespace al
48 #endif /* AL_THREADS_H */