wait_object: Refactor to allow waking up a single thread.

This commit is contained in:
bunnei 2018-01-07 16:33:41 -05:00
parent bc77a7580e
commit 0f6fbdb963
2 changed files with 30 additions and 17 deletions
src/core/hle/kernel

View file

@ -67,25 +67,32 @@ SharedPtr<Thread> WaitObject::GetHighestPriorityReadyThread() {
return candidate;
}
void WaitObject::WakeupWaitingThread(SharedPtr<Thread> thread) {
if (!thread)
return;
if (!thread->IsSleepingOnWaitAll()) {
Acquire(thread.get());
} else {
for (auto& object : thread->wait_objects) {
object->Acquire(thread.get());
}
}
// Invoke the wakeup callback before clearing the wait objects
if (thread->wakeup_callback)
thread->wakeup_callback(ThreadWakeupReason::Signal, thread, this);
for (auto& object : thread->wait_objects)
object->RemoveWaitingThread(thread.get());
thread->wait_objects.clear();
thread->ResumeFromWait();
}
void WaitObject::WakeupAllWaitingThreads() {
while (auto thread = GetHighestPriorityReadyThread()) {
if (!thread->IsSleepingOnWaitAll()) {
Acquire(thread.get());
} else {
for (auto& object : thread->wait_objects) {
object->Acquire(thread.get());
}
}
// Invoke the wakeup callback before clearing the wait objects
if (thread->wakeup_callback)
thread->wakeup_callback(ThreadWakeupReason::Signal, thread, this);
for (auto& object : thread->wait_objects)
object->RemoveWaitingThread(thread.get());
thread->wait_objects.clear();
thread->ResumeFromWait();
WakeupWaitingThread(thread);
}
}