diff options
author | bunnei <bunneidev@gmail.com> | 2020-02-13 03:46:00 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-13 03:46:00 +0100 |
commit | 8b9a56033acbcb707f8eeca578973db266052ee3 (patch) | |
tree | 0f20235a1d6d0c3f88daf21ac3bbc891e417d26b /src/core/hle/kernel/address_arbiter.cpp | |
parent | Merge pull request #3403 from lioncash/debug (diff) | |
parent | address_arbiter: Collapse loops in InsertThread() and RemoveThread() (diff) | |
download | yuzu-8b9a56033acbcb707f8eeca578973db266052ee3.tar yuzu-8b9a56033acbcb707f8eeca578973db266052ee3.tar.gz yuzu-8b9a56033acbcb707f8eeca578973db266052ee3.tar.bz2 yuzu-8b9a56033acbcb707f8eeca578973db266052ee3.tar.lz yuzu-8b9a56033acbcb707f8eeca578973db266052ee3.tar.xz yuzu-8b9a56033acbcb707f8eeca578973db266052ee3.tar.zst yuzu-8b9a56033acbcb707f8eeca578973db266052ee3.zip |
Diffstat (limited to 'src/core/hle/kernel/address_arbiter.cpp')
-rw-r--r-- | src/core/hle/kernel/address_arbiter.cpp | 53 |
1 files changed, 25 insertions, 28 deletions
diff --git a/src/core/hle/kernel/address_arbiter.cpp b/src/core/hle/kernel/address_arbiter.cpp index 2ea3dcb61..8475b698c 100644 --- a/src/core/hle/kernel/address_arbiter.cpp +++ b/src/core/hle/kernel/address_arbiter.cpp @@ -201,42 +201,39 @@ void AddressArbiter::HandleWakeupThread(std::shared_ptr<Thread> thread) { void AddressArbiter::InsertThread(std::shared_ptr<Thread> thread) { const VAddr arb_addr = thread->GetArbiterWaitAddress(); std::list<std::shared_ptr<Thread>>& thread_list = arb_threads[arb_addr]; - auto it = thread_list.begin(); - while (it != thread_list.end()) { - const std::shared_ptr<Thread>& current_thread = *it; - if (current_thread->GetPriority() >= thread->GetPriority()) { - thread_list.insert(it, thread); - return; - } - ++it; + + const auto iter = + std::find_if(thread_list.cbegin(), thread_list.cend(), [&thread](const auto& entry) { + return entry->GetPriority() >= thread->GetPriority(); + }); + + if (iter == thread_list.cend()) { + thread_list.push_back(std::move(thread)); + } else { + thread_list.insert(iter, std::move(thread)); } - thread_list.push_back(std::move(thread)); } void AddressArbiter::RemoveThread(std::shared_ptr<Thread> thread) { const VAddr arb_addr = thread->GetArbiterWaitAddress(); std::list<std::shared_ptr<Thread>>& thread_list = arb_threads[arb_addr]; - auto it = thread_list.begin(); - while (it != thread_list.end()) { - const std::shared_ptr<Thread>& current_thread = *it; - if (current_thread.get() == thread.get()) { - thread_list.erase(it); - return; - } - ++it; - } - UNREACHABLE(); + + const auto iter = std::find_if(thread_list.cbegin(), thread_list.cend(), + [&thread](const auto& entry) { return thread == entry; }); + + ASSERT(iter != thread_list.cend()); + + thread_list.erase(iter); } -std::vector<std::shared_ptr<Thread>> AddressArbiter::GetThreadsWaitingOnAddress(VAddr address) { - std::vector<std::shared_ptr<Thread>> result; - std::list<std::shared_ptr<Thread>>& thread_list = arb_threads[address]; - auto it = thread_list.begin(); - while (it != thread_list.end()) { - std::shared_ptr<Thread> current_thread = *it; - result.push_back(std::move(current_thread)); - ++it; +std::vector<std::shared_ptr<Thread>> AddressArbiter::GetThreadsWaitingOnAddress( + VAddr address) const { + const auto iter = arb_threads.find(address); + if (iter == arb_threads.cend()) { + return {}; } - return result; + + const std::list<std::shared_ptr<Thread>>& thread_list = iter->second; + return {thread_list.cbegin(), thread_list.cend()}; } } // namespace Kernel |