mirror of
https://github.com/yuzu-mirror/yuzu
synced 2024-11-24 01:33:03 +00:00
address_arbiter: Collapse loops in InsertThread() and RemoveThread()
Same behavior, but without the need to explicitly loop through everything manually.
This commit is contained in:
parent
9f2c703137
commit
be269e21a5
1 changed files with 17 additions and 19 deletions
|
@ -201,31 +201,29 @@ void AddressArbiter::HandleWakeupThread(std::shared_ptr<Thread> thread) {
|
||||||
void AddressArbiter::InsertThread(std::shared_ptr<Thread> thread) {
|
void AddressArbiter::InsertThread(std::shared_ptr<Thread> thread) {
|
||||||
const VAddr arb_addr = thread->GetArbiterWaitAddress();
|
const VAddr arb_addr = thread->GetArbiterWaitAddress();
|
||||||
std::list<std::shared_ptr<Thread>>& thread_list = arb_threads[arb_addr];
|
std::list<std::shared_ptr<Thread>>& thread_list = arb_threads[arb_addr];
|
||||||
auto it = thread_list.begin();
|
|
||||||
while (it != thread_list.end()) {
|
const auto iter =
|
||||||
const std::shared_ptr<Thread>& current_thread = *it;
|
std::find_if(thread_list.cbegin(), thread_list.cend(), [&thread](const auto& entry) {
|
||||||
if (current_thread->GetPriority() >= thread->GetPriority()) {
|
return entry->GetPriority() >= thread->GetPriority();
|
||||||
thread_list.insert(it, thread);
|
});
|
||||||
return;
|
|
||||||
}
|
if (iter == thread_list.cend()) {
|
||||||
++it;
|
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) {
|
void AddressArbiter::RemoveThread(std::shared_ptr<Thread> thread) {
|
||||||
const VAddr arb_addr = thread->GetArbiterWaitAddress();
|
const VAddr arb_addr = thread->GetArbiterWaitAddress();
|
||||||
std::list<std::shared_ptr<Thread>>& thread_list = arb_threads[arb_addr];
|
std::list<std::shared_ptr<Thread>>& thread_list = arb_threads[arb_addr];
|
||||||
auto it = thread_list.begin();
|
|
||||||
while (it != thread_list.end()) {
|
const auto iter = std::find_if(thread_list.cbegin(), thread_list.cend(),
|
||||||
const std::shared_ptr<Thread>& current_thread = *it;
|
[&thread](const auto& entry) { return thread == entry; });
|
||||||
if (current_thread.get() == thread.get()) {
|
|
||||||
thread_list.erase(it);
|
ASSERT(iter != thread_list.cend());
|
||||||
return;
|
|
||||||
}
|
thread_list.erase(iter);
|
||||||
++it;
|
|
||||||
}
|
|
||||||
UNREACHABLE();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<std::shared_ptr<Thread>> AddressArbiter::GetThreadsWaitingOnAddress(
|
std::vector<std::shared_ptr<Thread>> AddressArbiter::GetThreadsWaitingOnAddress(
|
||||||
|
|
Loading…
Reference in a new issue