| 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 | { |
no test coverage detected