From 0f6fbdb9632d4d67695b4f151884434b91441782 Mon Sep 17 00:00:00 2001 From: bunnei Date: Sun, 7 Jan 2018 16:33:41 -0500 Subject: [PATCH] wait_object: Refactor to allow waking up a single thread. --- src/core/hle/kernel/wait_object.cpp | 41 +++++++++++++++++------------ src/core/hle/kernel/wait_object.h | 6 +++++ 2 files changed, 30 insertions(+), 17 deletions(-) diff --git a/src/core/hle/kernel/wait_object.cpp b/src/core/hle/kernel/wait_object.cpp index 4695549081..c942a40fa7 100644 --- a/src/core/hle/kernel/wait_object.cpp +++ b/src/core/hle/kernel/wait_object.cpp @@ -67,25 +67,32 @@ SharedPtr WaitObject::GetHighestPriorityReadyThread() { return candidate; } +void WaitObject::WakeupWaitingThread(SharedPtr 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); } } diff --git a/src/core/hle/kernel/wait_object.h b/src/core/hle/kernel/wait_object.h index 8615781866..78bfd8c6c9 100644 --- a/src/core/hle/kernel/wait_object.h +++ b/src/core/hle/kernel/wait_object.h @@ -44,6 +44,12 @@ public: */ virtual void WakeupAllWaitingThreads(); + /** + * Wakes up a single thread waiting on this object. + * @param thread Thread that is waiting on this object to wakeup. + */ + void WakeupWaitingThread(SharedPtr thread); + /// Obtains the highest priority thread that is ready to run from this object's waiting list. SharedPtr GetHighestPriorityReadyThread();