DDraceNetwork Docs
threading.h
Go to the documentation of this file.
1#ifndef BASE_TL_THREADING_H
2#define BASE_TL_THREADING_H
3
4#include "../system.h"
5#include <atomic>
6
8{
10 // implement the counter separately, because the `sem_getvalue`-API is
11 // deprecated on macOS: https://stackoverflow.com/a/16655541
12 std::atomic_int m_Count{0};
13
14public:
17 CSemaphore(const CSemaphore &) = delete;
18 int GetApproximateValue() { return m_Count.load(); }
19 void Wait()
20 {
22 m_Count.fetch_sub(1);
23 }
24 void Signal()
25 {
26 m_Count.fetch_add(1);
28 }
29};
30
31#endif // BASE_TL_THREADING_H
Definition: threading.h:8
~CSemaphore()
Definition: threading.h:16
std::atomic_int m_Count
Definition: threading.h:12
int GetApproximateValue()
Definition: threading.h:18
CSemaphore()
Definition: threading.h:15
void Wait()
Definition: threading.h:19
SEMAPHORE m_Sem
Definition: threading.h:9
CSemaphore(const CSemaphore &)=delete
void Signal()
Definition: threading.h:24
void sphore_signal(SEMAPHORE *sem)
Definition: system.cpp:914
void sphore_destroy(SEMAPHORE *sem)
Definition: system.cpp:918
void sphore_init(SEMAPHORE *sem)
Definition: system.cpp:901
void sphore_wait(SEMAPHORE *sem)
Definition: system.cpp:905
sem_t SEMAPHORE
Definition: system.h:669