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:
@@ -1,4 +1,4 @@
|
|||||||
#include "stdafx.h"
|
#include "stdafx.h"
|
||||||
#include "Emu/System.h"
|
#include "Emu/System.h"
|
||||||
|
|
||||||
#include "Emu/Cell/PPUFunction.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);
|
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
|
// Yield command
|
||||||
const u64 start_time = get_system_time();
|
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;
|
static_cast<ppu_thread&>(cpu).start_time = start_time;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (prio < INT32_MAX && !unqueue(g_ppu, &cpu))
|
|
||||||
{
|
|
||||||
// Priority set
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Emplace current thread
|
// Emplace current thread
|
||||||
for (std::size_t i = 0; i <= g_ppu.size(); i++)
|
for (std::size_t i = 0; i <= g_ppu.size(); i++)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -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)
|
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);
|
lv2_obj::awake(thread, prio);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user