IOP: Fix WakeupThread waking up threads with other waittypes (#4047)

StreamListThread should have been deadlocked waiting for the
uninitialized LfoList semaphore, instead it'd get woken up by
WakeupThread erroneously.
This commit is contained in:
Ziemas
2025-12-08 23:44:45 +01:00
committed by GitHub
parent fde7b3befb
commit 5f1676d921
3 changed files with 25 additions and 5 deletions
+8 -3
View File
@@ -407,15 +407,20 @@ u32 StreamListThread() {
}
uVar9 = uVar9 + 1;
} while (uVar9 < 4);
SignalSema(EEStreamsList.sema);
RequestedStreamsList.unk2_init0 = 1;
SignalSema(RequestedStreamsList.sema);
WaitSema(EEPlayList.sema);
CheckPlayList(&EEPlayList);
SignalSema(EEPlayList.sema);
WaitSema(LfoList.sema);
CheckLfoList(&LfoList);
SignalSema(LfoList.sema);
// FIXME LfoList hasn't been initialised because of unimplemented
// streamlfo functions.
// WaitSema(LfoList.sema);
// CheckLfoList(&LfoList);
// SignalSema(LfoList.sema);
} while (true);
return 0;
}
+15 -1
View File
@@ -101,7 +101,14 @@ void IOP_Kernel::DelayThread(u32 usec) {
void IOP_Kernel::SleepThread() {
ASSERT(_currentThread);
_currentThread->state = IopThread::State::Suspend;
if (_currentThread->wakeupCount > 0) {
_currentThread->wakeupCount--;
return;
}
_currentThread->state = IopThread::State::Wait;
_currentThread->waitType = IopThread::Wait::Sleep;
leaveThread();
}
@@ -116,6 +123,13 @@ void IOP_Kernel::YieldThread() {
*/
void IOP_Kernel::WakeupThread(s32 id) {
ASSERT(id > 0);
auto& thread = threads.at(id);
if (thread.state != IopThread::State::Wait || thread.waitType != IopThread::Wait::Sleep) {
thread.wakeupCount++;
return;
}
threads.at(id).state = IopThread::State::Ready;
}
+2 -1
View File
@@ -53,7 +53,7 @@ struct IopThread {
Dormant,
};
enum class Wait { None, Semaphore, Delay, Messagebox, EventFlag };
enum class Wait { None, Sleep, Semaphore, Delay, Messagebox, EventFlag };
IopThread(std::string n, void (*f)(), s32 ID, u32 pri)
: name(std::move(n)), function(f), priority(pri), thID(ID) {
@@ -71,6 +71,7 @@ struct IopThread {
time_stamp resumeTime = {};
u32 priority = 0;
s32 thID = -1;
s32 wakeupCount = 0;
};
struct Semaphore {