summaryrefslogtreecommitdiff
path: root/src/core/hle/kernel/kernel.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/hle/kernel/kernel.cpp')
-rw-r--r--src/core/hle/kernel/kernel.cpp14
1 files changed, 4 insertions, 10 deletions
diff --git a/src/core/hle/kernel/kernel.cpp b/src/core/hle/kernel/kernel.cpp
index b8b69f9d0..653697843 100644
--- a/src/core/hle/kernel/kernel.cpp
+++ b/src/core/hle/kernel/kernel.cpp
@@ -34,14 +34,11 @@ void WaitObject::RemoveWaitingThread(Thread* thread) {
34 34
35SharedPtr<Thread> WaitObject::GetHighestPriorityReadyThread() { 35SharedPtr<Thread> WaitObject::GetHighestPriorityReadyThread() {
36 // Remove the threads that are ready or already running from our waitlist 36 // Remove the threads that are ready or already running from our waitlist
37 boost::range::remove_erase_if(waiting_threads, [](const SharedPtr<Thread>& thread) -> bool { 37 boost::range::remove_erase_if(waiting_threads, [](const SharedPtr<Thread>& thread) {
38 return thread->status == THREADSTATUS_RUNNING || thread->status == THREADSTATUS_READY; 38 return thread->status == THREADSTATUS_RUNNING || thread->status == THREADSTATUS_READY;
39 }); 39 });
40 40
41 if (waiting_threads.empty()) 41 Thread* candidate = nullptr;
42 return nullptr;
43
44 SharedPtr<Thread> candidate = nullptr;
45 s32 candidate_priority = THREADPRIO_LOWEST + 1; 42 s32 candidate_priority = THREADPRIO_LOWEST + 1;
46 43
47 for (const auto& thread : waiting_threads) { 44 for (const auto& thread : waiting_threads) {
@@ -52,7 +49,7 @@ SharedPtr<Thread> WaitObject::GetHighestPriorityReadyThread() {
52 return object->ShouldWait(); 49 return object->ShouldWait();
53 }); 50 });
54 if (ready_to_run) { 51 if (ready_to_run) {
55 candidate = thread; 52 candidate = thread.get();
56 candidate_priority = thread->current_priority; 53 candidate_priority = thread->current_priority;
57 } 54 }
58 } 55 }
@@ -61,9 +58,8 @@ SharedPtr<Thread> WaitObject::GetHighestPriorityReadyThread() {
61} 58}
62 59
63void WaitObject::WakeupAllWaitingThreads() { 60void WaitObject::WakeupAllWaitingThreads() {
64 // Wake up all threads that can be awoken, in priority order
65 while (auto thread = GetHighestPriorityReadyThread()) { 61 while (auto thread = GetHighestPriorityReadyThread()) {
66 if (thread->wait_objects.empty()) { 62 if (!thread->IsSleepingOnWaitAll()) {
67 Acquire(); 63 Acquire();
68 // Set the output index of the WaitSynchronizationN call to the index of this object. 64 // Set the output index of the WaitSynchronizationN call to the index of this object.
69 if (thread->wait_set_output) { 65 if (thread->wait_set_output) {
@@ -73,7 +69,6 @@ void WaitObject::WakeupAllWaitingThreads() {
73 } else { 69 } else {
74 for (auto object : thread->wait_objects) { 70 for (auto object : thread->wait_objects) {
75 object->Acquire(); 71 object->Acquire();
76 // Remove the thread from the object's waitlist
77 object->RemoveWaitingThread(thread.get()); 72 object->RemoveWaitingThread(thread.get());
78 } 73 }
79 // Note: This case doesn't update the output index of WaitSynchronizationN. 74 // Note: This case doesn't update the output index of WaitSynchronizationN.
@@ -81,7 +76,6 @@ void WaitObject::WakeupAllWaitingThreads() {
81 thread->wait_objects.clear(); 76 thread->wait_objects.clear();
82 } 77 }
83 78
84 // Set the result of the call to WaitSynchronization to RESULT_SUCCESS
85 thread->SetWaitSynchronizationResult(RESULT_SUCCESS); 79 thread->SetWaitSynchronizationResult(RESULT_SUCCESS);
86 thread->ResumeFromWait(); 80 thread->ResumeFromWait();
87 // Note: Removing the thread from the object's waitlist will be done by GetHighestPriorityReadyThread 81 // Note: Removing the thread from the object's waitlist will be done by GetHighestPriorityReadyThread