1
0
mirror of https://github.com/RPCS3/rpcs3.git synced 2024-11-22 18:53:28 +01:00
This commit is contained in:
Nekotekina 2017-01-29 22:52:07 +03:00
parent b21fce4d6f
commit aef5113d49

View File

@ -2055,6 +2055,9 @@ bool thread_ctrl::_wait_for(u64 usec)
} }
_lock{_this->m_mutex}; _lock{_this->m_mutex};
do
{
// Mutex is unlocked at the start and after the waiting
if (u32 sig = _this->m_signal.load()) if (u32 sig = _this->m_signal.load())
{ {
thread_ctrl::test(); thread_ctrl::test();
@ -2066,28 +2069,16 @@ bool thread_ctrl::_wait_for(u64 usec)
} }
} }
_this->m_mutex.wait(); if (usec == 0)
while (_this->m_cond.wait(_lock, usec))
{
if (u32 sig = _this->m_signal.load())
{
thread_ctrl::test();
if (sig & 1)
{
_this->m_signal &= ~1;
return true;
}
}
if (usec != -1)
{ {
// No timeout: return immediately
return false; return false;
} }
// Lock (semaphore)
_this->m_mutex.wait(); _this->m_mutex.wait();
// Double-check the value
if (u32 sig = _this->m_signal.load()) if (u32 sig = _this->m_signal.load())
{ {
if (sig & 2 && _this->m_exception) if (sig & 2 && _this->m_exception)
@ -2103,6 +2094,7 @@ bool thread_ctrl::_wait_for(u64 usec)
} }
} }
} }
while (_this->m_cond.wait(_lock, std::exchange(usec, usec == -1 ? -1 : 0)));
// Timeout // Timeout
return false; return false;