mirror of
https://github.com/open-goal/jak-project
synced 2026-08-21 23:00:45 -04:00
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:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user