MCPcopy Create free account
hub / github.com/cemu-project/Cemu / OSRunThread

Function OSRunThread

src/Cafe/OS/libs/coreinit/coreinit_Thread.cpp:501–542  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

499 }
500
501 bool OSRunThread(OSThread_t* thread, MPTR funcAddress, sint32 numParam, void* ptrParam)
502 {
503 __OSLockScheduler();
504
505 cemu_assert_debug(PPCInterpreter_getCurrentInstance() == nullptr || OSGetCurrentThread() != thread); // called on self, what should this function do?
506
507 if (thread->state != OSThread_t::THREAD_STATE::STATE_NONE && thread->state != OSThread_t::THREAD_STATE::STATE_MORIBUND)
508 {
509 // unsure about this case
510 cemuLog_logDebug(LogType::Force, "OSRunThread called on thread which cannot be ran");
511 __OSUnlockScheduler();
512 return false;
513 }
514
515 if (thread->state == OSThread_t::THREAD_STATE::STATE_MORIBUND)
516 {
517 thread->state = OSThread_t::THREAD_STATE::STATE_NONE;
518 coreinit::__OSDeactivateThread(thread);
519 coreinit::__OSRemoveThreadFromRunQueues(thread);
520 }
521
522 // set thread state
523 // todo - this should fully reinitialize the thread?
524
525 thread->entrypoint = funcAddress;
526 thread->context.srr0 = PPCInterpreter_makeCallableExportDepr(threadEntry);
527 thread->context.lr = _swapEndianU32(PPCInterpreter_makeCallableExportDepr(coreinitExport_OSExitThreadDepr));
528 thread->context.gpr[3] = _swapEndianU32(numParam);
529 thread->context.gpr[4] = _swapEndianU32(memory_getVirtualOffsetFromPointer(ptrParam));
530 thread->suspendCounter = 0; // verify
531
532 MPTR threadMPTR = memory_getVirtualOffsetFromPointer(thread);
533
534 coreinit::__OSActivateThread(thread);
535 thread->state = OSThread_t::THREAD_STATE::STATE_READY;
536
537 __OSAddReadyThreadToRunQueue(thread);
538
539 __OSUnlockScheduler();
540
541 return true;
542 }
543
544 void OSExitThread(sint32 exitValue)
545 {

Callers 1

cemu_initForGameFunction · 0.85

Calls 12

__OSLockSchedulerFunction · 0.85
cemu_assert_debugFunction · 0.85
OSGetCurrentThreadFunction · 0.85
cemuLog_logDebugFunction · 0.85
__OSUnlockSchedulerFunction · 0.85
__OSDeactivateThreadFunction · 0.85
_swapEndianU32Function · 0.85
__OSActivateThreadFunction · 0.85

Tested by

no test coverage detected