2013-10-27 08:14:13 -07:00
|
|
|
#ifndef AL_THREADS_H
|
|
|
|
#define AL_THREADS_H
|
|
|
|
|
2014-04-16 05:19:34 -07:00
|
|
|
#include <time.h>
|
|
|
|
|
2018-11-27 14:50:41 -08:00
|
|
|
#include <mutex>
|
|
|
|
|
2018-01-12 03:55:33 -08:00
|
|
|
#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
|
|
|
|
|
2014-04-16 01:39:11 -07:00
|
|
|
#ifdef _WIN32
|
|
|
|
#define WIN32_LEAN_AND_MEAN
|
|
|
|
#include <windows.h>
|
2018-11-27 14:50:41 -08:00
|
|
|
#elif defined(__APPLE__)
|
2018-10-15 16:40:57 +00:00
|
|
|
#include <dispatch/dispatch.h>
|
2018-11-27 14:50:41 -08:00
|
|
|
#else
|
2018-02-01 17:37:31 -08:00
|
|
|
#include <semaphore.h>
|
2018-11-26 20:34:16 -08:00
|
|
|
#endif
|
|
|
|
|
2018-11-17 06:07:04 -08:00
|
|
|
void althrd_setname(const char *name);
|
2014-04-16 05:19:34 -07:00
|
|
|
|
2018-11-27 13:41:30 -08:00
|
|
|
namespace al {
|
|
|
|
|
|
|
|
class semaphore {
|
2018-11-27 14:50:41 -08:00
|
|
|
#ifdef _WIN32
|
|
|
|
using native_type = HANDLE;
|
|
|
|
#elif defined(__APPLE__)
|
|
|
|
using native_type = dispatch_semaphore_t;
|
|
|
|
#else
|
|
|
|
using native_type = sem_t;
|
|
|
|
#endif
|
|
|
|
native_type mSem;
|
2018-11-27 13:41:30 -08:00
|
|
|
|
|
|
|
public:
|
|
|
|
semaphore(unsigned int initial=0);
|
|
|
|
semaphore(const semaphore&) = delete;
|
|
|
|
~semaphore();
|
|
|
|
|
|
|
|
semaphore& operator=(const semaphore&) = delete;
|
|
|
|
|
|
|
|
void post();
|
|
|
|
void wait() noexcept;
|
2018-11-29 13:34:06 -08:00
|
|
|
bool try_wait() noexcept;
|
2018-11-27 13:41:30 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace al
|
|
|
|
|
2013-10-27 08:14:13 -07:00
|
|
|
#endif /* AL_THREADS_H */
|