diff options
| author | 2016-12-06 19:15:32 -0500 | |
|---|---|---|
| committer | 2016-12-06 19:15:32 -0500 | |
| commit | 1f286b72a1b9e1fb98e37a01192f4e31b0ad4e1f (patch) | |
| tree | 03aad8985fa5a0522d237cfe417e05fbedd8cdb1 | |
| parent | Threading: Added some utility functions and const correctness. (diff) | |
| download | yuzu-1f286b72a1b9e1fb98e37a01192f4e31b0ad4e1f.tar.gz yuzu-1f286b72a1b9e1fb98e37a01192f4e31b0ad4e1f.tar.xz yuzu-1f286b72a1b9e1fb98e37a01192f4e31b0ad4e1f.zip | |
Improved the algorithm for GetHighestPriorityReadyThread.
| -rw-r--r-- | src/core/hle/kernel/kernel.cpp | 27 |
1 files changed, 13 insertions, 14 deletions
diff --git a/src/core/hle/kernel/kernel.cpp b/src/core/hle/kernel/kernel.cpp index 6d358def7..07f420099 100644 --- a/src/core/hle/kernel/kernel.cpp +++ b/src/core/hle/kernel/kernel.cpp | |||
| @@ -40,24 +40,23 @@ SharedPtr<Thread> WaitObject::GetHighestPriorityReadyThread() { | |||
| 40 | if (waiting_threads.empty()) | 40 | if (waiting_threads.empty()) |
| 41 | return nullptr; | 41 | return nullptr; |
| 42 | 42 | ||
| 43 | auto candidate_threads = waiting_threads; | 43 | SharedPtr<Thread> candidate = nullptr; |
| 44 | s32 candidate_priority = THREADPRIO_LOWEST + 1; | ||
| 44 | 45 | ||
| 45 | // Eliminate all threads that are waiting on more than one object, and not all of said objects are ready | 46 | for (const auto& thread : waiting_threads) { |
| 46 | candidate_threads.erase(std::remove_if(candidate_threads.begin(), candidate_threads.end(), [](const SharedPtr<Thread>& thread) -> bool { | 47 | if (thread->current_priority >= candidate_priority) |
| 47 | return std::any_of(thread->wait_objects.begin(), thread->wait_objects.end(), [](const SharedPtr<WaitObject>& object) -> bool { | 48 | continue; |
| 49 | |||
| 50 | bool ready_to_run = std::none_of(thread->wait_objects.begin(), thread->wait_objects.end(), [](const SharedPtr<WaitObject>& object) { | ||
| 48 | return object->ShouldWait(); | 51 | return object->ShouldWait(); |
| 49 | }); | 52 | }); |
| 50 | }), candidate_threads.end()); | 53 | if (ready_to_run) { |
| 51 | 54 | candidate = thread; | |
| 52 | // Return the thread with the lowest priority value (The one with the highest priority) | 55 | candidate_priority = thread->current_priority; |
| 53 | auto thread_itr = std::min_element(candidate_threads.begin(), candidate_threads.end(), [](const SharedPtr<Thread>& lhs, const SharedPtr<Thread>& rhs) { | 56 | } |
| 54 | return lhs->current_priority < rhs->current_priority; | 57 | } |
| 55 | }); | ||
| 56 | |||
| 57 | if (thread_itr == candidate_threads.end()) | ||
| 58 | return nullptr; | ||
| 59 | 58 | ||
| 60 | return *thread_itr; | 59 | return candidate; |
| 61 | } | 60 | } |
| 62 | 61 | ||
| 63 | void WaitObject::WakeupAllWaitingThreads() { | 62 | void WaitObject::WakeupAllWaitingThreads() { |