2014-06-20 21:56:19 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
class SSemaphore
|
|
|
|
{
|
|
|
|
const u32 m_max;
|
|
|
|
u32 m_count;
|
2014-06-25 00:16:44 +02:00
|
|
|
u32 m_in_order;
|
|
|
|
u32 m_out_order;
|
2014-06-25 23:59:23 +02:00
|
|
|
std::mutex m_cv_mutex;
|
|
|
|
std::mutex m_mutex;
|
2014-06-20 21:56:19 +02:00
|
|
|
std::condition_variable m_cond;
|
|
|
|
|
|
|
|
public:
|
|
|
|
SSemaphore(u32 value, u32 max = 1)
|
|
|
|
: m_max(max > 0 ? max : 0xffffffff)
|
|
|
|
, m_count(value > m_max ? m_max : value)
|
2014-06-25 00:16:44 +02:00
|
|
|
, m_in_order(0)
|
|
|
|
, m_out_order(0)
|
2014-06-20 21:56:19 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
SSemaphore()
|
|
|
|
: m_max(0xffffffff)
|
|
|
|
, m_count(0)
|
2014-06-25 00:16:44 +02:00
|
|
|
, m_in_order(0)
|
|
|
|
, m_out_order(0)
|
2014-06-20 21:56:19 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
~SSemaphore()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-06-25 00:16:44 +02:00
|
|
|
void wait();
|
2014-06-20 21:56:19 +02:00
|
|
|
|
|
|
|
bool try_wait();
|
|
|
|
|
2014-06-21 16:26:37 +02:00
|
|
|
void post();
|
2014-06-20 21:56:19 +02:00
|
|
|
|
|
|
|
bool post_and_wait();
|
|
|
|
};
|