aboutsummaryrefslogtreecommitdiffstats
path: root/common/threads.h
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2018-11-27 13:41:30 -0800
committerChris Robinson <[email protected]>2018-11-27 13:41:30 -0800
commitf26083e9edc6491f553aae951886d89b70288528 (patch)
tree1bb2b82ec786cbe2a98a3a5066c0be7c52dff1d1 /common/threads.h
parent3f745be1dc4df7ffeec89f1d90af41e139fb49db (diff)
Make and use a semaphore class
Diffstat (limited to 'common/threads.h')
-rw-r--r--common/threads.h20
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 */