mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-24 14:49:42 -06:00
Changed thread barrier and event to use a lamba wait predicate instead of a functor.
This commit is contained in:
@ -38,7 +38,7 @@ class Event
|
|||||||
public:
|
public:
|
||||||
Event()
|
Event()
|
||||||
: is_set(false)
|
: is_set(false)
|
||||||
{};
|
{}
|
||||||
|
|
||||||
void Set()
|
void Set()
|
||||||
{
|
{
|
||||||
@ -53,34 +53,20 @@ public:
|
|||||||
void Wait()
|
void Wait()
|
||||||
{
|
{
|
||||||
std::unique_lock<std::mutex> lk(m_mutex);
|
std::unique_lock<std::mutex> lk(m_mutex);
|
||||||
m_condvar.wait(lk, IsSet(this));
|
m_condvar.wait(lk, [&]{ return is_set; });
|
||||||
is_set = false;
|
is_set = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Reset()
|
void Reset()
|
||||||
{
|
{
|
||||||
std::unique_lock<std::mutex> lk(m_mutex);
|
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
|
// no other action required, since wait loops on
|
||||||
|
// the predicate and any lingering signal will get
|
||||||
|
// cleared on the first iteration
|
||||||
is_set = false;
|
is_set = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
class IsSet
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
IsSet(const Event* ev)
|
|
||||||
: m_event(ev)
|
|
||||||
{}
|
|
||||||
|
|
||||||
bool operator()()
|
|
||||||
{
|
|
||||||
return m_event->is_set;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
const Event* const m_event;
|
|
||||||
};
|
|
||||||
|
|
||||||
volatile bool is_set;
|
volatile bool is_set;
|
||||||
std::condition_variable m_condvar;
|
std::condition_variable m_condvar;
|
||||||
std::mutex m_mutex;
|
std::mutex m_mutex;
|
||||||
@ -110,28 +96,12 @@ public:
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
m_condvar.wait(lk, IsDoneWating(this));
|
m_condvar.wait(lk, [&]{ return (0 == m_waiting); });
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
class IsDoneWating
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
IsDoneWating(const Barrier* bar)
|
|
||||||
: m_bar(bar)
|
|
||||||
{}
|
|
||||||
|
|
||||||
bool operator()()
|
|
||||||
{
|
|
||||||
return (0 == m_bar->m_waiting);
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
const Barrier* const m_bar;
|
|
||||||
};
|
|
||||||
|
|
||||||
std::condition_variable m_condvar;
|
std::condition_variable m_condvar;
|
||||||
std::mutex m_mutex;
|
std::mutex m_mutex;
|
||||||
const size_t m_count;
|
const size_t m_count;
|
||||||
|
Reference in New Issue
Block a user