ppu: Fix threads scheduler

*Set priority under a lock
*Fix yield command making threads going out of scheduler control by removing it from the queue (not a bug that affects compatibility)
This commit is contained in:
eladash 2018-10-18 23:02:03 +03:00 committed by Ivan
parent 3fd17e43a3
commit 3332a10052
2 changed files with 11 additions and 9 deletions

View file

@ -1,4 +1,4 @@
#include "stdafx.h"
#include "stdafx.h"
#include "Emu/System.h"
#include "Emu/Cell/PPUFunction.h"
@ -1063,7 +1063,15 @@ void lv2_obj::awake(cpu_thread& cpu, u32 prio)
std::lock_guard lock(g_mutex);
if (prio == -4)
if (prio < INT32_MAX)
{
// Priority set
if (static_cast<ppu_thread&>(cpu).prio.exchange(prio) == prio || !unqueue(g_ppu, &cpu))
{
return;
}
}
else if (prio == -4)
{
// Yield command
const u64 start_time = get_system_time();
@ -1087,12 +1095,6 @@ void lv2_obj::awake(cpu_thread& cpu, u32 prio)
static_cast<ppu_thread&>(cpu).start_time = start_time;
}
if (prio < INT32_MAX && !unqueue(g_ppu, &cpu))
{
// Priority set
return;
}
// Emplace current thread
for (std::size_t i = 0; i <= g_ppu.size(); i++)
{

View file

@ -206,7 +206,7 @@ error_code sys_ppu_thread_set_priority(ppu_thread& ppu, u32 thread_id, s32 prio)
const auto thread = idm::check<named_thread<ppu_thread>>(thread_id, [&](ppu_thread& thread)
{
if (thread.prio != prio && thread.prio.exchange(prio) != prio)
if (thread.prio != prio)
{
lv2_obj::awake(thread, prio);
}