#ifndef AL_THREADS_H #define AL_THREADS_H #include #if defined(__GNUC__) && defined(__i386__) /* force_align_arg_pointer is required for proper function arguments aligning * when SSE code is used. Some systems (Windows, QNX) do not guarantee our * thread functions will be properly aligned on the stack, even though GCC may * generate code with the assumption that it is. */ #define FORCE_ALIGN __attribute__((force_align_arg_pointer)) #else #define FORCE_ALIGN #endif #ifdef __cplusplus #include extern "C" { #endif enum { althrd_success = 0, althrd_error, althrd_nomem, althrd_timedout, althrd_busy }; #ifdef _WIN32 #define WIN32_LEAN_AND_MEAN #include typedef HANDLE alsem_t; #else #include #include #include #ifdef __APPLE__ #include #else /* !__APPLE__ */ #include #endif /* __APPLE__ */ #ifdef __APPLE__ typedef dispatch_semaphore_t alsem_t; #else /* !__APPLE__ */ typedef sem_t alsem_t; #endif /* __APPLE__ */ #endif void althrd_setname(const char *name); int alsem_init(alsem_t *sem, unsigned int initial); void alsem_destroy(alsem_t *sem); int alsem_post(alsem_t *sem); int alsem_wait(alsem_t *sem); int alsem_trywait(alsem_t *sem); #ifdef __cplusplus } // extern "C" namespace al { class semaphore { alsem_t mSem; public: semaphore(unsigned int initial=0); semaphore(const semaphore&) = delete; ~semaphore(); semaphore& operator=(const semaphore&) = delete; void post(); void wait() noexcept; int trywait() noexcept; }; } // namespace al #endif #endif /* AL_THREADS_H */