kern: cleanup KThread, optimize/normalize KThreadQueue/KWaitObject

This commit is contained in:
Michael Scire 2020-12-01 15:19:29 -08:00 committed by SciresM
parent 1852fe8612
commit 8b2ed36698
10 changed files with 58 additions and 168 deletions

View file

@ -26,7 +26,7 @@ namespace ams::kern::arch::arm64 {
/* Send KDebug event for this thread's creation. */
{
KScopedInterruptEnable ei;
KDebug::OnDebugEvent(ams::svc::DebugEvent_CreateThread, GetCurrentThread().GetId(), GetInteger(GetCurrentThread().GetThreadLocalRegionAddress()), GetCurrentThread().GetEntrypoint());
KDebug::OnDebugEvent(ams::svc::DebugEvent_CreateThread, GetCurrentThread().GetId(), GetInteger(GetCurrentThread().GetThreadLocalRegionAddress()));
}
/* Handle any pending dpc. */

View file

@ -327,7 +327,7 @@ namespace ams::kern {
it->SetDebugAttached();
/* Send the event. */
this->PushDebugEvent(ams::svc::DebugEvent_CreateThread, it->GetId(), GetInteger(it->GetThreadLocalRegionAddress()), it->GetEntrypoint());
this->PushDebugEvent(ams::svc::DebugEvent_CreateThread, it->GetId(), GetInteger(it->GetThreadLocalRegionAddress()));
}
}
}
@ -682,7 +682,6 @@ namespace ams::kern {
/* Set the thread creation info. */
info->info.create_thread.thread_id = param0;
info->info.create_thread.tls_address = param1;
info->info.create_thread.entrypoint = param2;
}
break;
case ams::svc::DebugEvent_ExitProcess:
@ -842,7 +841,6 @@ namespace ams::kern {
{
out->info.create_thread.thread_id = info->info.create_thread.thread_id;
out->info.create_thread.tls_address = info->info.create_thread.tls_address;
out->info.create_thread.entrypoint = info->info.create_thread.entrypoint;
}
break;
case ams::svc::DebugEvent_ExitProcess:

View file

@ -74,7 +74,7 @@ namespace ams::kern {
/* If we can reply, do so. */
if (!this->current_request->IsTerminationRequested()) {
MESOSPHERE_ASSERT(this->current_request->GetState() == KThread::ThreadState_Waiting);
MESOSPHERE_ASSERT(this->current_request == this->request_queue.GetFront());
MESOSPHERE_ASSERT(this->request_queue.begin() != this->request_queue.end() && this->current_request == std::addressof(*this->request_queue.begin()));
std::memcpy(this->current_request->GetLightSessionData(), server_thread->GetLightSessionData(), KLightSession::DataSize);
this->request_queue.WakeupThread(this->current_request);
}
@ -110,8 +110,8 @@ namespace ams::kern {
R_UNLESS(!this->parent->IsServerClosed(), svc::ResultSessionClosed());
/* If we have a request available, use it. */
if (this->current_request == nullptr && this->request_queue.IsEmpty()) {
this->current_request = this->request_queue.GetFront();
if (this->current_request == nullptr && !this->request_queue.IsEmpty()) {
this->current_request = std::addressof(*this->request_queue.begin());
this->current_request->Open();
this->server_thread = server_thread;
break;
@ -148,7 +148,7 @@ namespace ams::kern {
/* Reply to the current request. */
if (!this->current_request->IsTerminationRequested()) {
MESOSPHERE_ASSERT(this->current_request->GetState() == KThread::ThreadState_Waiting);
MESOSPHERE_ASSERT(this->current_request == this->request_queue.GetFront());
MESOSPHERE_ASSERT(this->request_queue.begin() != this->request_queue.end() && this->current_request == std::addressof(*this->request_queue.begin()));
this->request_queue.WakeupThread(this->current_request);
this->current_request->SetSyncedObject(nullptr, svc::ResultSessionClosed());
}

View file

@ -98,7 +98,6 @@ namespace ams::kern {
/* Set sync booleans. */
this->signaled = false;
this->ipc_cancelled = false;
this->termination_requested = false;
this->wait_cancelled = false;
this->cancellable = false;
@ -119,7 +118,6 @@ namespace ams::kern {
this->waiting_lock = nullptr;
/* Initialize sleeping queue. */
this->sleeping_queue_entry.Initialize();
this->sleeping_queue = nullptr;
/* Set suspend flags. */
@ -141,7 +139,6 @@ namespace ams::kern {
/* We have no waiters, but we do have an entrypoint. */
this->num_kernel_waiters = 0;
this->entrypoint = reinterpret_cast<uintptr_t>(func);
/* Set our current core id. */
this->current_core_id = core;
@ -172,7 +169,7 @@ namespace ams::kern {
const bool is_64_bit = this->parent ? this->parent->Is64Bit() : IsDefault64Bit;
const bool is_user = (type == ThreadType_User);
const bool is_main = (type == ThreadType_Main);
this->thread_context.Initialize(this->entrypoint, reinterpret_cast<uintptr_t>(this->GetStackTop()), GetInteger(user_stack_top), arg, is_user, is_64_bit, is_main);
this->thread_context.Initialize(reinterpret_cast<uintptr_t>(func), reinterpret_cast<uintptr_t>(this->GetStackTop()), GetInteger(user_stack_top), arg, is_user, is_64_bit, is_main);
/* Setup the stack parameters. */
StackParameters &sp = this->GetStackParameters();

View file

@ -21,19 +21,8 @@ namespace ams::kern {
MESOSPHERE_ASSERT(KScheduler::IsSchedulerLockedByCurrentThread());
/* Wake up all the waiting threads. */
Entry *entry = std::addressof(this->root);
while (true) {
/* Get the next thread. */
KThread *thread = entry->GetNext();
if (thread == nullptr) {
break;
}
/* Wake it up. */
thread->Wakeup();
/* Advance. */
entry = std::addressof(thread->GetSleepingQueueEntry());
for (KThread &thread : this->wait_list) {
thread.Wakeup();
}
}
@ -73,7 +62,7 @@ namespace ams::kern {
this->OnTimer();
} else {
/* Otherwise, sleep until the timeout occurs. */
this->Enqueue(cur_thread);
this->wait_list.push_back(GetCurrentThread());
cur_thread->SetState(KThread::ThreadState_Waiting);
cur_thread->SetSyncedObject(nullptr, svc::ResultTimedOut());
}
@ -93,7 +82,7 @@ namespace ams::kern {
/* Remove the thread from our queue. */
if (timeout != 0) {
this->Remove(cur_thread);
this->wait_list.erase(this->wait_list.iterator_to(GetCurrentThread()));
}
}