summaryrefslogtreecommitdiff
path: root/src/core/hle/kernel/kernel.cpp
diff options
context:
space:
mode:
authorGravatar Yuri Kunde Schlesner2017-05-29 15:45:30 -0700
committerGravatar Yuri Kunde Schlesner2017-05-29 16:16:46 -0700
commit64ecf81a3cf6d6e0a4e4e915e1da2f0bcf2f1cb4 (patch)
treef34182d882d614273dd709f0029039743bc58c21 /src/core/hle/kernel/kernel.cpp
parentKernel: Removed HandleTable::GetWaitObject (diff)
downloadyuzu-64ecf81a3cf6d6e0a4e4e915e1da2f0bcf2f1cb4.tar.gz
yuzu-64ecf81a3cf6d6e0a4e4e915e1da2f0bcf2f1cb4.tar.xz
yuzu-64ecf81a3cf6d6e0a4e4e915e1da2f0bcf2f1cb4.zip
Kernel: Move WaitObject to a separate file
Now that HandleTable doesn't directly depend on WaitObject anymore, this can be separated from the main kernel.h header.
Diffstat (limited to 'src/core/hle/kernel/kernel.cpp')
-rw-r--r--src/core/hle/kernel/kernel.cpp79
1 files changed, 0 insertions, 79 deletions
diff --git a/src/core/hle/kernel/kernel.cpp b/src/core/hle/kernel/kernel.cpp
index 7f84e01aa..b0af5b9b8 100644
--- a/src/core/hle/kernel/kernel.cpp
+++ b/src/core/hle/kernel/kernel.cpp
@@ -20,85 +20,6 @@ namespace Kernel {
20unsigned int Object::next_object_id; 20unsigned int Object::next_object_id;
21HandleTable g_handle_table; 21HandleTable g_handle_table;
22 22
23void WaitObject::AddWaitingThread(SharedPtr<Thread> thread) {
24 auto itr = std::find(waiting_threads.begin(), waiting_threads.end(), thread);
25 if (itr == waiting_threads.end())
26 waiting_threads.push_back(std::move(thread));
27}
28
29void WaitObject::RemoveWaitingThread(Thread* thread) {
30 auto itr = std::find(waiting_threads.begin(), waiting_threads.end(), thread);
31 // If a thread passed multiple handles to the same object,
32 // the kernel might attempt to remove the thread from the object's
33 // waiting threads list multiple times.
34 if (itr != waiting_threads.end())
35 waiting_threads.erase(itr);
36}
37
38SharedPtr<Thread> WaitObject::GetHighestPriorityReadyThread() {
39 Thread* candidate = nullptr;
40 s32 candidate_priority = THREADPRIO_LOWEST + 1;
41
42 for (const auto& thread : waiting_threads) {
43 // The list of waiting threads must not contain threads that are not waiting to be awakened.
44 ASSERT_MSG(thread->status == THREADSTATUS_WAIT_SYNCH_ANY ||
45 thread->status == THREADSTATUS_WAIT_SYNCH_ALL,
46 "Inconsistent thread statuses in waiting_threads");
47
48 if (thread->current_priority >= candidate_priority)
49 continue;
50
51 if (ShouldWait(thread.get()))
52 continue;
53
54 // A thread is ready to run if it's either in THREADSTATUS_WAIT_SYNCH_ANY or
55 // in THREADSTATUS_WAIT_SYNCH_ALL and the rest of the objects it is waiting on are ready.
56 bool ready_to_run = true;
57 if (thread->status == THREADSTATUS_WAIT_SYNCH_ALL) {
58 ready_to_run = std::none_of(thread->wait_objects.begin(), thread->wait_objects.end(),
59 [&thread](const SharedPtr<WaitObject>& object) {
60 return object->ShouldWait(thread.get());
61 });
62 }
63
64 if (ready_to_run) {
65 candidate = thread.get();
66 candidate_priority = thread->current_priority;
67 }
68 }
69
70 return candidate;
71}
72
73void WaitObject::WakeupAllWaitingThreads() {
74 while (auto thread = GetHighestPriorityReadyThread()) {
75 if (!thread->IsSleepingOnWaitAll()) {
76 Acquire(thread.get());
77 // Set the output index of the WaitSynchronizationN call to the index of this object.
78 if (thread->wait_set_output) {
79 thread->SetWaitSynchronizationOutput(thread->GetWaitObjectIndex(this));
80 thread->wait_set_output = false;
81 }
82 } else {
83 for (auto& object : thread->wait_objects) {
84 object->Acquire(thread.get());
85 }
86 // Note: This case doesn't update the output index of WaitSynchronizationN.
87 }
88
89 for (auto& object : thread->wait_objects)
90 object->RemoveWaitingThread(thread.get());
91 thread->wait_objects.clear();
92
93 thread->SetWaitSynchronizationResult(RESULT_SUCCESS);
94 thread->ResumeFromWait();
95 }
96}
97
98const std::vector<SharedPtr<Thread>>& WaitObject::GetWaitingThreads() const {
99 return waiting_threads;
100}
101
102HandleTable::HandleTable() { 23HandleTable::HandleTable() {
103 next_generation = 1; 24 next_generation = 1;
104 Clear(); 25 Clear();