Common: Move the Event class to a separate file, and add tests for it. Fix includes everywhere to match this.

This commit is contained in:
Pierre Bourdon
2014-04-14 01:15:23 +02:00
parent f9fb39d383
commit 6bdcbad3e4
22 changed files with 132 additions and 53 deletions

View File

@ -32,45 +32,6 @@ int CurrentThreadId();
void SetThreadAffinity(std::thread::native_handle_type thread, u32 mask);
void SetCurrentThreadAffinity(u32 mask);
class Event
{
public:
Event()
: is_set(false)
{}
void Set()
{
std::lock_guard<std::mutex> lk(m_mutex);
if (!is_set)
{
is_set = true;
m_condvar.notify_one();
}
}
void Wait()
{
std::unique_lock<std::mutex> lk(m_mutex);
m_condvar.wait(lk, [&]{ return is_set; });
is_set = false;
}
void Reset()
{
std::unique_lock<std::mutex> lk(m_mutex);
// no other action required, since wait loops on
// the predicate and any lingering signal will get
// cleared on the first iteration
is_set = false;
}
private:
volatile bool is_set;
std::condition_variable m_condvar;
std::mutex m_mutex;
};
// TODO: doesn't work on windows with (count > 2)
class Barrier
{