void OSCancelThread(OSThread *thread) { bool reschedule = false; OSLockScheduler(); if (thread->requestFlag == OSThreadRequest::Suspend) { OSWakeupThreadWaitForSuspensionNoLock(&thread->suspendQueue, -1); reschedule = true; } if (thread->suspendCounter != 0) { if (thread->cancelState == 0) { OSResumeThreadNoLock(thread, thread->suspendCounter); reschedule = true; } } if (reschedule) { OSRescheduleNoLock(); } thread->suspendCounter = 0; thread->needSuspend = 0; thread->requestFlag = OSThreadRequest::Cancel; OSUnlockScheduler(); if (OSGetCurrentThread() == thread) { OSExitThread(-1); } }
void OSExitThread(int value) { auto thread = OSGetCurrentThread(); OSLockScheduler(); thread->exitValue = value; if (thread->attr & OSThreadAttributes::Detached) { thread->state = OSThreadState::None; } else { thread->state = OSThreadState::Moribund; } OSWakeupThreadNoLock(&thread->joinQueue); OSWakeupThreadWaitForSuspensionNoLock(&thread->suspendQueue, -1); OSUnlockScheduler(); gProcessor.exit(); }