summaryrefslogtreecommitdiff
path: root/src/core/hle/kernel/thread.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/hle/kernel/thread.cpp')
-rw-r--r--src/core/hle/kernel/thread.cpp38
1 files changed, 19 insertions, 19 deletions
diff --git a/src/core/hle/kernel/thread.cpp b/src/core/hle/kernel/thread.cpp
index e15590c49..9e2e15c8e 100644
--- a/src/core/hle/kernel/thread.cpp
+++ b/src/core/hle/kernel/thread.cpp
@@ -1,6 +1,6 @@
1// Copyright 2014 Citra Emulator Project / PPSSPP Project 1// Copyright 2014 Citra Emulator Project / PPSSPP Project
2// Licensed under GPLv2 2// Licensed under GPLv2
3// Refer to the license.txt file included. 3// Refer to the license.txt file included.
4 4
5#include <algorithm> 5#include <algorithm>
6#include <list> 6#include <list>
@@ -113,7 +113,7 @@ void ResetThread(Thread* t, u32 arg, s32 lowest_priority) {
113 t->context.pc = t->context.reg_15 = t->entry_point; 113 t->context.pc = t->context.reg_15 = t->entry_point;
114 t->context.sp = t->stack_top; 114 t->context.sp = t->stack_top;
115 t->context.cpsr = 0x1F; // Usermode 115 t->context.cpsr = 0x1F; // Usermode
116 116
117 // TODO(bunnei): This instructs the CPU core to start the execution as if it is "resuming" a 117 // TODO(bunnei): This instructs the CPU core to start the execution as if it is "resuming" a
118 // thread. This is somewhat Sky-Eye specific, and should be re-architected in the future to be 118 // thread. This is somewhat Sky-Eye specific, and should be re-architected in the future to be
119 // agnostic of the CPU core. 119 // agnostic of the CPU core.
@@ -148,7 +148,7 @@ inline bool VerifyWait(const Handle& handle, WaitType type, Handle wait_handle)
148 Thread* thread = g_object_pool.GetFast<Thread>(handle); 148 Thread* thread = g_object_pool.GetFast<Thread>(handle);
149 _assert_msg_(KERNEL, (thread != nullptr), "called, but thread is nullptr!"); 149 _assert_msg_(KERNEL, (thread != nullptr), "called, but thread is nullptr!");
150 150
151 if (type != thread->wait_type || wait_handle != thread->wait_handle) 151 if (type != thread->wait_type || wait_handle != thread->wait_handle)
152 return false; 152 return false;
153 153
154 return true; 154 return true;
@@ -158,7 +158,7 @@ inline bool VerifyWait(const Handle& handle, WaitType type, Handle wait_handle)
158void StopThread(Handle handle, const char* reason) { 158void StopThread(Handle handle, const char* reason) {
159 Thread* thread = g_object_pool.GetFast<Thread>(handle); 159 Thread* thread = g_object_pool.GetFast<Thread>(handle);
160 _assert_msg_(KERNEL, (thread != nullptr), "called, but thread is nullptr!"); 160 _assert_msg_(KERNEL, (thread != nullptr), "called, but thread is nullptr!");
161 161
162 ChangeReadyState(thread, false); 162 ChangeReadyState(thread, false);
163 thread->status = THREADSTATUS_DORMANT; 163 thread->status = THREADSTATUS_DORMANT;
164 for (size_t i = 0; i < thread->waiting_threads.size(); ++i) { 164 for (size_t i = 0; i < thread->waiting_threads.size(); ++i) {
@@ -181,7 +181,7 @@ void ChangeThreadState(Thread* t, ThreadStatus new_status) {
181 } 181 }
182 ChangeReadyState(t, (new_status & THREADSTATUS_READY) != 0); 182 ChangeReadyState(t, (new_status & THREADSTATUS_READY) != 0);
183 t->status = new_status; 183 t->status = new_status;
184 184
185 if (new_status == THREADSTATUS_WAIT) { 185 if (new_status == THREADSTATUS_WAIT) {
186 if (t->wait_type == WAITTYPE_NONE) { 186 if (t->wait_type == WAITTYPE_NONE) {
187 ERROR_LOG(KERNEL, "Waittype none not allowed"); 187 ERROR_LOG(KERNEL, "Waittype none not allowed");
@@ -216,7 +216,7 @@ Handle ArbitrateHighestPriorityThread(u32 arbiter, u32 address) {
216 216
217/// Arbitrate all threads currently waiting 217/// Arbitrate all threads currently waiting
218void ArbitrateAllThreads(u32 arbiter, u32 address) { 218void ArbitrateAllThreads(u32 arbiter, u32 address) {
219 219
220 // Iterate through threads, find highest priority thread that is waiting to be arbitrated... 220 // Iterate through threads, find highest priority thread that is waiting to be arbitrated...
221 for (const auto& handle : g_thread_queue) { 221 for (const auto& handle : g_thread_queue) {
222 222
@@ -238,11 +238,11 @@ void CallThread(Thread* t) {
238/// Switches CPU context to that of the specified thread 238/// Switches CPU context to that of the specified thread
239void SwitchContext(Thread* t) { 239void SwitchContext(Thread* t) {
240 Thread* cur = GetCurrentThread(); 240 Thread* cur = GetCurrentThread();
241 241
242 // Save context for current thread 242 // Save context for current thread
243 if (cur) { 243 if (cur) {
244 SaveContext(cur->context); 244 SaveContext(cur->context);
245 245
246 if (cur->IsRunning()) { 246 if (cur->IsRunning()) {
247 ChangeReadyState(cur, true); 247 ChangeReadyState(cur, true);
248 } 248 }
@@ -263,7 +263,7 @@ void SwitchContext(Thread* t) {
263Thread* NextThread() { 263Thread* NextThread() {
264 Handle next; 264 Handle next;
265 Thread* cur = GetCurrentThread(); 265 Thread* cur = GetCurrentThread();
266 266
267 if (cur && cur->IsRunning()) { 267 if (cur && cur->IsRunning()) {
268 next = g_thread_ready_queue.pop_first_better(cur->current_priority); 268 next = g_thread_ready_queue.pop_first_better(cur->current_priority);
269 } else { 269 } else {
@@ -319,7 +319,7 @@ void DebugThreadQueue() {
319Thread* CreateThread(Handle& handle, const char* name, u32 entry_point, s32 priority, 319Thread* CreateThread(Handle& handle, const char* name, u32 entry_point, s32 priority,
320 s32 processor_id, u32 stack_top, int stack_size) { 320 s32 processor_id, u32 stack_top, int stack_size) {
321 321
322 _assert_msg_(KERNEL, (priority >= THREADPRIO_HIGHEST && priority <= THREADPRIO_LOWEST), 322 _assert_msg_(KERNEL, (priority >= THREADPRIO_HIGHEST && priority <= THREADPRIO_LOWEST),
323 "CreateThread priority=%d, outside of allowable range!", priority) 323 "CreateThread priority=%d, outside of allowable range!", priority)
324 324
325 Thread* thread = new Thread; 325 Thread* thread = new Thread;
@@ -351,7 +351,7 @@ Handle CreateThread(const char* name, u32 entry_point, s32 priority, u32 arg, s3
351 return -1; 351 return -1;
352 } 352 }
353 if ((u32)stack_size < 0x200) { 353 if ((u32)stack_size < 0x200) {
354 ERROR_LOG(KERNEL, "CreateThread(name=%s): invalid stack_size=0x%08X", name, 354 ERROR_LOG(KERNEL, "CreateThread(name=%s): invalid stack_size=0x%08X", name,
355 stack_size); 355 stack_size);
356 return -1; 356 return -1;
357 } 357 }
@@ -368,7 +368,7 @@ Handle CreateThread(const char* name, u32 entry_point, s32 priority, u32 arg, s3
368 return -1; 368 return -1;
369 } 369 }
370 Handle handle; 370 Handle handle;
371 Thread* thread = CreateThread(handle, name, entry_point, priority, processor_id, stack_top, 371 Thread* thread = CreateThread(handle, name, entry_point, priority, processor_id, stack_top,
372 stack_size); 372 stack_size);
373 373
374 ResetThread(thread, arg, 0); 374 ResetThread(thread, arg, 0);
@@ -423,19 +423,19 @@ Result SetThreadPriority(Handle handle, s32 priority) {
423/// Sets up the primary application thread 423/// Sets up the primary application thread
424Handle SetupMainThread(s32 priority, int stack_size) { 424Handle SetupMainThread(s32 priority, int stack_size) {
425 Handle handle; 425 Handle handle;
426 426
427 // Initialize new "main" thread 427 // Initialize new "main" thread
428 Thread* thread = CreateThread(handle, "main", Core::g_app_core->GetPC(), priority, 428 Thread* thread = CreateThread(handle, "main", Core::g_app_core->GetPC(), priority,
429 THREADPROCESSORID_0, Memory::SCRATCHPAD_VADDR_END, stack_size); 429 THREADPROCESSORID_0, Memory::SCRATCHPAD_VADDR_END, stack_size);
430 430
431 ResetThread(thread, 0, 0); 431 ResetThread(thread, 0, 0);
432 432
433 // If running another thread already, set it to "ready" state 433 // If running another thread already, set it to "ready" state
434 Thread* cur = GetCurrentThread(); 434 Thread* cur = GetCurrentThread();
435 if (cur && cur->IsRunning()) { 435 if (cur && cur->IsRunning()) {
436 ChangeReadyState(cur, true); 436 ChangeReadyState(cur, true);
437 } 437 }
438 438
439 // Run new "main" thread 439 // Run new "main" thread
440 SetCurrentThread(thread); 440 SetCurrentThread(thread);
441 thread->status = THREADSTATUS_RUNNING; 441 thread->status = THREADSTATUS_RUNNING;
@@ -452,12 +452,12 @@ void Reschedule() {
452 HLE::g_reschedule = false; 452 HLE::g_reschedule = false;
453 if (next > 0) { 453 if (next > 0) {
454 INFO_LOG(KERNEL, "context switch 0x%08X -> 0x%08X", prev->GetHandle(), next->GetHandle()); 454 INFO_LOG(KERNEL, "context switch 0x%08X -> 0x%08X", prev->GetHandle(), next->GetHandle());
455 455
456 SwitchContext(next); 456 SwitchContext(next);
457 457
458 // Hack - There is no mechanism yet to waken the primary thread if it has been put to sleep 458 // Hack - There is no mechanism yet to waken the primary thread if it has been put to sleep
459 // by a simulated VBLANK thread switch. So, we'll just immediately set it to "ready" again. 459 // by a simulated VBLANK thread switch. So, we'll just immediately set it to "ready" again.
460 // This results in the current thread yielding on a VBLANK once, and then it will be 460 // This results in the current thread yielding on a VBLANK once, and then it will be
461 // immediately placed back in the queue for execution. 461 // immediately placed back in the queue for execution.
462 if (prev->wait_type == WAITTYPE_VBLANK) { 462 if (prev->wait_type == WAITTYPE_VBLANK) {
463 ResumeThreadFromWait(prev->GetHandle()); 463 ResumeThreadFromWait(prev->GetHandle());