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

@ -312,33 +312,22 @@ void ppu_thread::cmd_pop(u32 count)
cmd64 ppu_thread::cmd_wait()
{
std::unique_lock<named_thread> lock(*this, std::defer_lock);
while (true)
{
if (UNLIKELY(test(state)))
{
if (lock) lock.unlock();
if (check_state()) // check_status() requires unlocked mutex
if (check_state())
{
return cmd64{};
}
}
// Lightweight queue doesn't care about mutex state
if (cmd64 result = cmd_queue[cmd_queue.peek()].exchange(cmd64{}))
{
return result;
}
if (!lock)
{
lock.lock();
continue;
}
thread_ctrl::wait(); // Waiting requires locked mutex
thread_ctrl::wait();
}
}