summaryrefslogtreecommitdiff
path: root/src/core/hle/kernel/scheduler.cpp
diff options
context:
space:
mode:
authorGravatar Lioncash2018-10-03 18:47:57 -0400
committerGravatar Lioncash2018-10-04 00:14:15 -0400
commitbaed7e1fba99c3f1932c6a41ad1496d1b6490a5a (patch)
tree004a9784a05294531e2f3975205f856a96b1a1ef /src/core/hle/kernel/scheduler.cpp
parentMerge pull request #1330 from raven02/tlds (diff)
downloadyuzu-baed7e1fba99c3f1932c6a41ad1496d1b6490a5a.tar.gz
yuzu-baed7e1fba99c3f1932c6a41ad1496d1b6490a5a.tar.xz
yuzu-baed7e1fba99c3f1932c6a41ad1496d1b6490a5a.zip
kernel/thread: Make all instance variables private
Many of the member variables of the thread class aren't even used outside of the class itself, so there's no need to make those variables public. This change follows in the steps of the previous changes that made other kernel types' members private. The main motivation behind this is that the Thread class will likely change in the future as emulation becomes more accurate, and letting random bits of the emulator access data members of the Thread class directly makes it a pain to shuffle around and/or modify internals. Having all data members public like this also makes it difficult to reason about certain bits of behavior without first verifying what parts of the core actually use them. Everything being public also generally follows the tendency for changes to be introduced in completely different translation units that would otherwise be better introduced as an addition to the Thread class' public interface.
Diffstat (limited to 'src/core/hle/kernel/scheduler.cpp')
-rw-r--r--src/core/hle/kernel/scheduler.cpp36
1 files changed, 18 insertions, 18 deletions
diff --git a/src/core/hle/kernel/scheduler.cpp b/src/core/hle/kernel/scheduler.cpp
index 1e82cfffb..cfd6e1bad 100644
--- a/src/core/hle/kernel/scheduler.cpp
+++ b/src/core/hle/kernel/scheduler.cpp
@@ -38,10 +38,10 @@ Thread* Scheduler::PopNextReadyThread() {
38 Thread* next = nullptr; 38 Thread* next = nullptr;
39 Thread* thread = GetCurrentThread(); 39 Thread* thread = GetCurrentThread();
40 40
41 if (thread && thread->status == ThreadStatus::Running) { 41 if (thread && thread->GetStatus() == ThreadStatus::Running) {
42 // We have to do better than the current thread. 42 // We have to do better than the current thread.
43 // This call returns null when that's not possible. 43 // This call returns null when that's not possible.
44 next = ready_queue.pop_first_better(thread->current_priority); 44 next = ready_queue.pop_first_better(thread->GetPriority());
45 if (!next) { 45 if (!next) {
46 // Otherwise just keep going with the current thread 46 // Otherwise just keep going with the current thread
47 next = thread; 47 next = thread;
@@ -58,22 +58,21 @@ void Scheduler::SwitchContext(Thread* new_thread) {
58 58
59 // Save context for previous thread 59 // Save context for previous thread
60 if (previous_thread) { 60 if (previous_thread) {
61 previous_thread->last_running_ticks = CoreTiming::GetTicks(); 61 cpu_core.SaveContext(previous_thread->GetContext());
62 cpu_core.SaveContext(previous_thread->context);
63 // Save the TPIDR_EL0 system register in case it was modified. 62 // Save the TPIDR_EL0 system register in case it was modified.
64 previous_thread->tpidr_el0 = cpu_core.GetTPIDR_EL0(); 63 previous_thread->SetTPIDR_EL0(cpu_core.GetTPIDR_EL0());
65 64
66 if (previous_thread->status == ThreadStatus::Running) { 65 if (previous_thread->GetStatus() == ThreadStatus::Running) {
67 // This is only the case when a reschedule is triggered without the current thread 66 // This is only the case when a reschedule is triggered without the current thread
68 // yielding execution (i.e. an event triggered, system core time-sliced, etc) 67 // yielding execution (i.e. an event triggered, system core time-sliced, etc)
69 ready_queue.push_front(previous_thread->current_priority, previous_thread); 68 ready_queue.push_front(previous_thread->GetPriority(), previous_thread);
70 previous_thread->status = ThreadStatus::Ready; 69 previous_thread->SetStatus(ThreadStatus::Ready);
71 } 70 }
72 } 71 }
73 72
74 // Load context of new thread 73 // Load context of new thread
75 if (new_thread) { 74 if (new_thread) {
76 ASSERT_MSG(new_thread->status == ThreadStatus::Ready, 75 ASSERT_MSG(new_thread->GetStatus() == ThreadStatus::Ready,
77 "Thread must be ready to become running."); 76 "Thread must be ready to become running.");
78 77
79 // Cancel any outstanding wakeup events for this thread 78 // Cancel any outstanding wakeup events for this thread
@@ -83,15 +82,16 @@ void Scheduler::SwitchContext(Thread* new_thread) {
83 82
84 current_thread = new_thread; 83 current_thread = new_thread;
85 84
86 ready_queue.remove(new_thread->current_priority, new_thread); 85 ready_queue.remove(new_thread->GetPriority(), new_thread);
87 new_thread->status = ThreadStatus::Running; 86 new_thread->SetStatus(ThreadStatus::Running);
88 87
89 if (previous_process != current_thread->owner_process) { 88 const auto thread_owner_process = current_thread->GetOwnerProcess();
90 Core::CurrentProcess() = current_thread->owner_process; 89 if (previous_process != thread_owner_process) {
90 Core::CurrentProcess() = thread_owner_process;
91 SetCurrentPageTable(&Core::CurrentProcess()->VMManager().page_table); 91 SetCurrentPageTable(&Core::CurrentProcess()->VMManager().page_table);
92 } 92 }
93 93
94 cpu_core.LoadContext(new_thread->context); 94 cpu_core.LoadContext(new_thread->GetContext());
95 cpu_core.SetTlsAddress(new_thread->GetTLSAddress()); 95 cpu_core.SetTlsAddress(new_thread->GetTLSAddress());
96 cpu_core.SetTPIDR_EL0(new_thread->GetTPIDR_EL0()); 96 cpu_core.SetTPIDR_EL0(new_thread->GetTPIDR_EL0());
97 cpu_core.ClearExclusiveState(); 97 cpu_core.ClearExclusiveState();
@@ -136,14 +136,14 @@ void Scheduler::RemoveThread(Thread* thread) {
136void Scheduler::ScheduleThread(Thread* thread, u32 priority) { 136void Scheduler::ScheduleThread(Thread* thread, u32 priority) {
137 std::lock_guard<std::mutex> lock(scheduler_mutex); 137 std::lock_guard<std::mutex> lock(scheduler_mutex);
138 138
139 ASSERT(thread->status == ThreadStatus::Ready); 139 ASSERT(thread->GetStatus() == ThreadStatus::Ready);
140 ready_queue.push_back(priority, thread); 140 ready_queue.push_back(priority, thread);
141} 141}
142 142
143void Scheduler::UnscheduleThread(Thread* thread, u32 priority) { 143void Scheduler::UnscheduleThread(Thread* thread, u32 priority) {
144 std::lock_guard<std::mutex> lock(scheduler_mutex); 144 std::lock_guard<std::mutex> lock(scheduler_mutex);
145 145
146 ASSERT(thread->status == ThreadStatus::Ready); 146 ASSERT(thread->GetStatus() == ThreadStatus::Ready);
147 ready_queue.remove(priority, thread); 147 ready_queue.remove(priority, thread);
148} 148}
149 149
@@ -151,8 +151,8 @@ void Scheduler::SetThreadPriority(Thread* thread, u32 priority) {
151 std::lock_guard<std::mutex> lock(scheduler_mutex); 151 std::lock_guard<std::mutex> lock(scheduler_mutex);
152 152
153 // If thread was ready, adjust queues 153 // If thread was ready, adjust queues
154 if (thread->status == ThreadStatus::Ready) 154 if (thread->GetStatus() == ThreadStatus::Ready)
155 ready_queue.move(thread, thread->current_priority, priority); 155 ready_queue.move(thread, thread->GetPriority(), priority);
156 else 156 else
157 ready_queue.prepare(priority); 157 ready_queue.prepare(priority);
158} 158}