Don't assume the total length of certain arrays
[openal-soft.git] / common / threads.h
blobff571a662f4b2383b84684c34262cfe0b1f2a765
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 #ifdef _WIN32
15 #define WIN32_LEAN_AND_MEAN
16 #include <windows.h>
17 #elif defined(__APPLE__)
18 #include <dispatch/dispatch.h>
19 #else
20 #include <semaphore.h>
21 #endif
23 void althrd_setname(const char *name);
25 namespace al {
27 class semaphore {
28 #ifdef _WIN32
29 using native_type = HANDLE;
30 #elif defined(__APPLE__)
31 using native_type = dispatch_semaphore_t;
32 #else
33 using native_type = sem_t;
34 #endif
35 native_type mSem;
37 public:
38 semaphore(unsigned int initial=0);
39 semaphore(const semaphore&) = delete;
40 ~semaphore();
42 semaphore& operator=(const semaphore&) = delete;
44 void post();
45 void wait() noexcept;
46 bool try_wait() noexcept;
49 } // namespace al
51 #endif /* AL_THREADS_H */