diff options
Diffstat (limited to '')
| -rw-r--r-- | src/core/hle/kernel/address_arbiter.cpp | 53 | ||||
| -rw-r--r-- | src/core/hle/kernel/address_arbiter.h | 2 |
2 files changed, 26 insertions, 29 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) { | |||
| 201 | void AddressArbiter::InsertThread(std::shared_ptr<Thread> thread) { | 201 | void AddressArbiter::InsertThread(std::shared_ptr<Thread> thread) { |
| 202 | const VAddr arb_addr = thread->GetArbiterWaitAddress(); | 202 | const VAddr arb_addr = thread->GetArbiterWaitAddress(); |
| 203 | std::list<std::shared_ptr<Thread>>& thread_list = arb_threads[arb_addr]; | 203 | std::list<std::shared_ptr<Thread>>& thread_list = arb_threads[arb_addr]; |
| 204 | auto it = thread_list.begin(); | 204 | |
| 205 | while (it != thread_list.end()) { | 205 | const auto iter = |
| 206 | const std::shared_ptr<Thread>& current_thread = *it; | 206 | std::find_if(thread_list.cbegin(), thread_list.cend(), [&thread](const auto& entry) { |
| 207 | if (current_thread->GetPriority() >= thread->GetPriority()) { | 207 | return entry->GetPriority() >= thread->GetPriority(); |
| 208 | thread_list.insert(it, thread); | 208 | }); |
| 209 | return; | 209 | |
| 210 | } | 210 | if (iter == thread_list.cend()) { |
| 211 | ++it; | 211 | thread_list.push_back(std::move(thread)); |
| 212 | } else { | ||
| 213 | thread_list.insert(iter, std::move(thread)); | ||
| 212 | } | 214 | } |
| 213 | thread_list.push_back(std::move(thread)); | ||
| 214 | } | 215 | } |
| 215 | 216 | ||
| 216 | void AddressArbiter::RemoveThread(std::shared_ptr<Thread> thread) { | 217 | void AddressArbiter::RemoveThread(std::shared_ptr<Thread> thread) { |
| 217 | const VAddr arb_addr = thread->GetArbiterWaitAddress(); | 218 | const VAddr arb_addr = thread->GetArbiterWaitAddress(); |
| 218 | std::list<std::shared_ptr<Thread>>& thread_list = arb_threads[arb_addr]; | 219 | std::list<std::shared_ptr<Thread>>& thread_list = arb_threads[arb_addr]; |
| 219 | auto it = thread_list.begin(); | 220 | |
| 220 | while (it != thread_list.end()) { | 221 | const auto iter = std::find_if(thread_list.cbegin(), thread_list.cend(), |
| 221 | const std::shared_ptr<Thread>& current_thread = *it; | 222 | [&thread](const auto& entry) { return thread == entry; }); |
| 222 | if (current_thread.get() == thread.get()) { | 223 | |
| 223 | thread_list.erase(it); | 224 | ASSERT(iter != thread_list.cend()); |
| 224 | return; | 225 | |
| 225 | } | 226 | thread_list.erase(iter); |
| 226 | ++it; | ||
| 227 | } | ||
| 228 | UNREACHABLE(); | ||
| 229 | } | 227 | } |
| 230 | 228 | ||
| 231 | std::vector<std::shared_ptr<Thread>> AddressArbiter::GetThreadsWaitingOnAddress(VAddr address) { | 229 | std::vector<std::shared_ptr<Thread>> AddressArbiter::GetThreadsWaitingOnAddress( |
| 232 | std::vector<std::shared_ptr<Thread>> result; | 230 | VAddr address) const { |
| 233 | std::list<std::shared_ptr<Thread>>& thread_list = arb_threads[address]; | 231 | const auto iter = arb_threads.find(address); |
| 234 | auto it = thread_list.begin(); | 232 | if (iter == arb_threads.cend()) { |
| 235 | while (it != thread_list.end()) { | 233 | return {}; |
| 236 | std::shared_ptr<Thread> current_thread = *it; | ||
| 237 | result.push_back(std::move(current_thread)); | ||
| 238 | ++it; | ||
| 239 | } | 234 | } |
| 240 | return result; | 235 | |
| 236 | const std::list<std::shared_ptr<Thread>>& thread_list = iter->second; | ||
| 237 | return {thread_list.cbegin(), thread_list.cend()}; | ||
| 241 | } | 238 | } |
| 242 | } // namespace Kernel | 239 | } // namespace Kernel |
diff --git a/src/core/hle/kernel/address_arbiter.h b/src/core/hle/kernel/address_arbiter.h index 386983e54..f958eee5a 100644 --- a/src/core/hle/kernel/address_arbiter.h +++ b/src/core/hle/kernel/address_arbiter.h | |||
| @@ -86,7 +86,7 @@ private: | |||
| 86 | void RemoveThread(std::shared_ptr<Thread> thread); | 86 | void RemoveThread(std::shared_ptr<Thread> thread); |
| 87 | 87 | ||
| 88 | // Gets the threads waiting on an address. | 88 | // Gets the threads waiting on an address. |
| 89 | std::vector<std::shared_ptr<Thread>> GetThreadsWaitingOnAddress(VAddr address); | 89 | std::vector<std::shared_ptr<Thread>> GetThreadsWaitingOnAddress(VAddr address) const; |
| 90 | 90 | ||
| 91 | /// List of threads waiting for a address arbiter | 91 | /// List of threads waiting for a address arbiter |
| 92 | std::unordered_map<VAddr, std::list<std::shared_ptr<Thread>>> arb_threads; | 92 | std::unordered_map<VAddr, std::list<std::shared_ptr<Thread>>> arb_threads; |