diff options
author | Chris Robinson <chris.kcat@gmail.com> | 2018-11-27 13:41:30 -0800 |
---|---|---|
committer | Chris Robinson <chris.kcat@gmail.com> | 2018-11-27 13:41:30 -0800 |
commit | f26083e9edc6491f553aae951886d89b70288528 (patch) | |
tree | 1bb2b82ec786cbe2a98a3a5066c0be7c52dff1d1 /common/threads.h | |
parent | 3f745be1dc4df7ffeec89f1d90af41e139fb49db (diff) |
Make and use a semaphore class
Diffstat (limited to 'common/threads.h')
-rw-r--r-- | common/threads.h | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/common/threads.h b/common/threads.h index a357b494..03a3899c 100644 --- a/common/threads.h +++ b/common/threads.h @@ -63,6 +63,26 @@ 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 */ |