mirror of
				https://git.suyu.dev/suyu/suyu
				synced 2025-10-30 07:29:02 -05: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:
		| @@ -201,31 +201,29 @@ 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( | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Lioncash
					Lioncash