Fix uninitialized count variable and naming convention

This commit is contained in:
Zwelf 2022-01-09 16:22:07 +01:00
parent f7f49ee5df
commit dcabb07707

View file

@ -9,21 +9,21 @@ class CSemaphore
SEMAPHORE m_Sem;
// implement the counter seperatly, because the `sem_getvalue`-API is
// deprecated on macOS: https://stackoverflow.com/a/16655541
std::atomic_int count;
std::atomic_int m_Count{0};
public:
CSemaphore() { sphore_init(&m_Sem); }
~CSemaphore() { sphore_destroy(&m_Sem); }
CSemaphore(const CSemaphore &) = delete;
int GetApproximateValue() { return count.load(); }
int GetApproximateValue() { return m_Count.load(); }
void Wait()
{
sphore_wait(&m_Sem);
count.fetch_sub(1);
m_Count.fetch_sub(1);
}
void Signal()
{
count.fetch_add(1);
m_Count.fetch_add(1);
sphore_signal(&m_Sem);
}
};