2014-06-20 19:56:19 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
class SSemaphore
|
|
|
|
{
|
|
|
|
const u32 m_max;
|
|
|
|
u32 m_count;
|
2014-06-24 22:16:44 +00:00
|
|
|
u32 m_in_order;
|
|
|
|
u32 m_out_order;
|
2014-06-25 21:59:23 +00:00
|
|
|
std::mutex m_cv_mutex;
|
|
|
|
std::mutex m_mutex;
|
2014-06-20 19:56:19 +00: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-24 22:16:44 +00:00
|
|
|
, m_in_order(0)
|
|
|
|
, m_out_order(0)
|
2014-06-20 19:56:19 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
SSemaphore()
|
|
|
|
: m_max(0xffffffff)
|
|
|
|
, m_count(0)
|
2014-06-24 22:16:44 +00:00
|
|
|
, m_in_order(0)
|
|
|
|
, m_out_order(0)
|
2014-06-20 19:56:19 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
~SSemaphore()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-06-24 22:16:44 +00:00
|
|
|
void wait();
|
2014-06-20 19:56:19 +00:00
|
|
|
|
|
|
|
bool try_wait();
|
|
|
|
|
2014-06-21 14:26:37 +00:00
|
|
|
void post();
|
2014-06-20 19:56:19 +00:00
|
|
|
|
|
|
|
bool post_and_wait();
|
|
|
|
};
|