Thread.cpp refinement

Hide thread mutex
Safe notify() method
Other refactoring
This commit is contained in:
Nekotekina 2016-09-07 01:38:52 +03:00
parent da878c36bd
commit a5a2d43d7c
35 changed files with 532 additions and 591 deletions

View file

@ -13,6 +13,8 @@ class semaphore_base
void imp_post(s32 _old);
friend class semaphore_lock;
protected:
explicit constexpr semaphore_base(s32 value)
: m_value{value}
@ -108,3 +110,34 @@ public:
return Max;
}
};
class semaphore_lock
{
semaphore_base& m_base;
void lock()
{
m_base.wait();
}
void unlock()
{
m_base.post(INT32_MAX);
}
friend class cond_variable;
public:
explicit semaphore_lock(const semaphore_lock&) = delete;
semaphore_lock(semaphore_base& sema)
: m_base(sema)
{
lock();
}
~semaphore_lock()
{
unlock();
}
};