Torque3D/Engine/lib/openal-soft/common/threads.h

49 lines
1.1 KiB
C
Raw Normal View History

2016-10-22 09:22:33 +10:00
#ifndef AL_THREADS_H
#define AL_THREADS_H
2018-05-09 20:48:18 +10: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
#if defined(__APPLE__)
#include <dispatch/dispatch.h>
#elif !defined(_WIN32)
#include <semaphore.h>
2016-10-22 09:22:33 +10:00
#endif
void althrd_setname(const char *name);
2016-10-22 09:22:33 +10:00
namespace al {
2016-10-22 09:22:33 +10:00
class semaphore {
2016-10-22 09:22:33 +10:00
#ifdef _WIN32
using native_type = void*;
#elif defined(__APPLE__)
using native_type = dispatch_semaphore_t;
2016-10-22 09:22:33 +10:00
#else
using native_type = sem_t;
2016-10-22 09:22:33 +10:00
#endif
native_type mSem;
2018-05-09 20:48:18 +10:00
public:
semaphore(unsigned int initial=0);
semaphore(const semaphore&) = delete;
~semaphore();
2016-10-22 09:22:33 +10:00
semaphore& operator=(const semaphore&) = delete;
2016-10-22 09:22:33 +10:00
void post();
void wait() noexcept;
bool try_wait() noexcept;
};
2016-10-22 09:22:33 +10:00
} // namespace al
2016-10-22 09:22:33 +10:00
#endif /* AL_THREADS_H */