kern: split Process/Thread exit to separate WorkerTaskManagers

This commit is contained in:
Michael Scire 2023-10-11 09:57:58 -07:00
parent e61f20ce18
commit bc6d207469
4 changed files with 15 additions and 10 deletions

View File

@ -25,7 +25,8 @@ namespace ams::kern {
static constexpr s32 ExitWorkerPriority = 11;
enum WorkerType {
WorkerType_Exit,
WorkerType_ExitThread,
WorkerType_ExitProcess,
WorkerType_Count,
};

View File

@ -491,7 +491,7 @@ namespace ams::kern {
MESOSPHERE_LOG("KProcess::Exit() pid=%ld name=%-12s\n", m_process_id, m_name);
/* Register the process as a work task. */
KWorkerTaskManager::AddTask(KWorkerTaskManager::WorkerType_Exit, this);
KWorkerTaskManager::AddTask(KWorkerTaskManager::WorkerType_ExitProcess, this);
}
/* Exit the current thread. */
@ -536,7 +536,7 @@ namespace ams::kern {
MESOSPHERE_LOG("KProcess::Terminate() FAIL pid=%ld name=%-12s\n", m_process_id, m_name);
/* Register the process as a work task. */
KWorkerTaskManager::AddTask(KWorkerTaskManager::WorkerType_Exit, this);
KWorkerTaskManager::AddTask(KWorkerTaskManager::WorkerType_ExitProcess, this);
}
}

View File

@ -476,10 +476,6 @@ namespace ams::kern {
m_parent->ClearRunningThread(this);
}
/* Signal. */
m_signaled = true;
KSynchronizationObject::NotifyAvailable();
/* Call the on thread termination handler. */
KThreadContext::OnThreadTerminating(this);
@ -507,6 +503,13 @@ namespace ams::kern {
cpu::SynchronizeCores(m_parent->GetPhysicalCoreMask());
}
/* Acquire the scheduler lock. */
KScopedSchedulerLock sl;
/* Signal. */
m_signaled = true;
KSynchronizationObject::NotifyAvailable();
/* Close the thread. */
this->Close();
}
@ -1328,7 +1331,7 @@ namespace ams::kern {
this->StartTermination();
/* Register the thread as a work task. */
KWorkerTaskManager::AddTask(KWorkerTaskManager::WorkerType_Exit, this);
KWorkerTaskManager::AddTask(KWorkerTaskManager::WorkerType_ExitThread, this);
}
MESOSPHERE_PANIC("KThread::Exit() would return");

View File

@ -115,8 +115,9 @@ namespace ams::kern {
/* Perform more core-0 specific initialization. */
if (core_id == 0) {
/* Initialize the exit worker manager, so that threads and processes may exit cleanly. */
Kernel::GetWorkerTaskManager(KWorkerTaskManager::WorkerType_Exit).Initialize(KWorkerTaskManager::ExitWorkerPriority);
/* Initialize the exit worker managers, so that threads and processes may exit cleanly. */
Kernel::GetWorkerTaskManager(KWorkerTaskManager::WorkerType_ExitThread).Initialize(KWorkerTaskManager::ExitWorkerPriority);
Kernel::GetWorkerTaskManager(KWorkerTaskManager::WorkerType_ExitProcess).Initialize(KWorkerTaskManager::ExitWorkerPriority);
/* Setup so that we may sleep later, and reserve memory for secure applets. */
KSystemControl::InitializePhase2();