diff options
author | Subv <subv2112@gmail.com> | 2016-12-08 16:34:53 +0100 |
---|---|---|
committer | Subv <subv2112@gmail.com> | 2016-12-09 18:23:09 +0100 |
commit | 17b29d8865ea4d96c18f7e1671bd6d0f01eab95f (patch) | |
tree | 20137ff3eed145ae36db64ccf4b54cf37384c82c /src/core/hle/kernel | |
parent | Use boost remove_erase_if instead of the erase-remove idiom (diff) | |
download | yuzu-17b29d8865ea4d96c18f7e1671bd6d0f01eab95f.tar yuzu-17b29d8865ea4d96c18f7e1671bd6d0f01eab95f.tar.gz yuzu-17b29d8865ea4d96c18f7e1671bd6d0f01eab95f.tar.bz2 yuzu-17b29d8865ea4d96c18f7e1671bd6d0f01eab95f.tar.lz yuzu-17b29d8865ea4d96c18f7e1671bd6d0f01eab95f.tar.xz yuzu-17b29d8865ea4d96c18f7e1671bd6d0f01eab95f.tar.zst yuzu-17b29d8865ea4d96c18f7e1671bd6d0f01eab95f.zip |
Diffstat (limited to 'src/core/hle/kernel')
-rw-r--r-- | src/core/hle/kernel/kernel.cpp | 14 | ||||
-rw-r--r-- | src/core/hle/kernel/kernel.h | 5 | ||||
-rw-r--r-- | src/core/hle/kernel/thread.h | 5 |
3 files changed, 11 insertions, 13 deletions
diff --git a/src/core/hle/kernel/kernel.cpp b/src/core/hle/kernel/kernel.cpp index b8b69f9d0..653697843 100644 --- a/src/core/hle/kernel/kernel.cpp +++ b/src/core/hle/kernel/kernel.cpp @@ -34,14 +34,11 @@ void WaitObject::RemoveWaitingThread(Thread* thread) { SharedPtr<Thread> WaitObject::GetHighestPriorityReadyThread() { // Remove the threads that are ready or already running from our waitlist - boost::range::remove_erase_if(waiting_threads, [](const SharedPtr<Thread>& thread) -> bool { + boost::range::remove_erase_if(waiting_threads, [](const SharedPtr<Thread>& thread) { return thread->status == THREADSTATUS_RUNNING || thread->status == THREADSTATUS_READY; }); - if (waiting_threads.empty()) - return nullptr; - - SharedPtr<Thread> candidate = nullptr; + Thread* candidate = nullptr; s32 candidate_priority = THREADPRIO_LOWEST + 1; for (const auto& thread : waiting_threads) { @@ -52,7 +49,7 @@ SharedPtr<Thread> WaitObject::GetHighestPriorityReadyThread() { return object->ShouldWait(); }); if (ready_to_run) { - candidate = thread; + candidate = thread.get(); candidate_priority = thread->current_priority; } } @@ -61,9 +58,8 @@ SharedPtr<Thread> WaitObject::GetHighestPriorityReadyThread() { } void WaitObject::WakeupAllWaitingThreads() { - // Wake up all threads that can be awoken, in priority order while (auto thread = GetHighestPriorityReadyThread()) { - if (thread->wait_objects.empty()) { + if (!thread->IsSleepingOnWaitAll()) { Acquire(); // Set the output index of the WaitSynchronizationN call to the index of this object. if (thread->wait_set_output) { @@ -73,7 +69,6 @@ void WaitObject::WakeupAllWaitingThreads() { } else { for (auto object : thread->wait_objects) { object->Acquire(); - // Remove the thread from the object's waitlist object->RemoveWaitingThread(thread.get()); } // Note: This case doesn't update the output index of WaitSynchronizationN. @@ -81,7 +76,6 @@ void WaitObject::WakeupAllWaitingThreads() { thread->wait_objects.clear(); } - // Set the result of the call to WaitSynchronization to RESULT_SUCCESS thread->SetWaitSynchronizationResult(RESULT_SUCCESS); thread->ResumeFromWait(); // Note: Removing the thread from the object's waitlist will be done by GetHighestPriorityReadyThread diff --git a/src/core/hle/kernel/kernel.h b/src/core/hle/kernel/kernel.h index eb5a3bf7e..4227d2373 100644 --- a/src/core/hle/kernel/kernel.h +++ b/src/core/hle/kernel/kernel.h @@ -152,7 +152,10 @@ public: */ void RemoveWaitingThread(Thread* thread); - /// Wake up all threads waiting on this object + /** + * Wake up all threads waiting on this object that can be awoken, in priority order, + * and set the synchronization result and output of the thread. + */ void WakeupAllWaitingThreads(); /// Obtains the highest priority thread that is ready to run from this object's waiting list. diff --git a/src/core/hle/kernel/thread.h b/src/core/hle/kernel/thread.h index 1b29fb3a3..4c254cb9d 100644 --- a/src/core/hle/kernel/thread.h +++ b/src/core/hle/kernel/thread.h @@ -7,6 +7,7 @@ #include <string> #include <unordered_map> #include <vector> +#include <boost/container/flat_map.hpp> #include <boost/container/flat_set.hpp> #include "common/common_types.h" #include "core/core.h" @@ -153,7 +154,7 @@ public: * its wait list to become ready, as a result of a WaitSynchronizationN call * with wait_all = true, or a ReplyAndReceive call. */ - bool IsWaitingAll() const { + bool IsSleepingOnWaitAll() const { return !wait_objects.empty(); } @@ -183,7 +184,7 @@ public: /// This is only populated when the thread should wait for all the objects to become ready. std::vector<SharedPtr<WaitObject>> wait_objects; - std::unordered_map<int, s32> wait_objects_index; ///< Mapping of Object ids to their position in the last waitlist that this object waited on. + boost::container::flat_map<int, s32> wait_objects_index; ///< Mapping of Object ids to their position in the last waitlist that this object waited on. VAddr wait_address; ///< If waiting on an AddressArbiter, this is the arbitration address |