kern: SvcGetLastThreadInfo, SvcGetDebugFutureThreadInfo

This commit is contained in:
Michael Scire
2020-07-30 16:31:58 -07:00
committed by SciresM
parent 0993ae0685
commit 51084c0837
13 changed files with 325 additions and 18 deletions

View File

@@ -18,7 +18,86 @@
namespace ams::kern {
void KWaitObject::OnTimer() {
MESOSPHERE_UNIMPLEMENTED();
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());
}
}
Result KWaitObject::Synchronize(s64 timeout) {
/* Perform the wait. */
KHardwareTimer *timer = nullptr;
KThread *cur_thread = GetCurrentThreadPointer();
{
KScopedSchedulerLock sl;
/* Check that the thread isn't terminating. */
R_UNLESS(!cur_thread->IsTerminationRequested(), svc::ResultTerminationRequested());
/* Verify that nothing else is already waiting on the object. */
if (timeout > 0) {
R_UNLESS(!this->timer_used, svc::ResultBusy());
}
/* Check that we're not already in use. */
if (timeout >= 0) {
/* Verify the timer isn't already in use. */
R_UNLESS(!this->timer_used, svc::ResultBusy());
}
/* If we need to, register our timeout. */
if (timeout > 0) {
/* Mark that we're using the timer. */
this->timer_used = true;
/* Use the timer. */
timer = std::addressof(Kernel::GetHardwareTimer());
timer->RegisterAbsoluteTask(this, timeout);
}
if (timeout == 0) {
/* If we're timed out immediately, just wake up the thread. */
this->OnTimer();
} else {
/* Otherwise, sleep until the timeout occurs. */
this->Enqueue(cur_thread);
cur_thread->SetState(KThread::ThreadState_Waiting);
cur_thread->SetSyncedObject(nullptr, svc::ResultTimedOut());
}
}
/* Cleanup as necessary. */
{
KScopedSchedulerLock sl;
/* Remove from the timer. */
if (timeout > 0) {
MESOSPHERE_ASSERT(this->timer_used);
MESOSPHERE_ASSERT(timer != nullptr);
timer->CancelTask(this);
this->timer_used = false;
}
/* Remove the thread from our queue. */
if (timeout != 0) {
this->Remove(cur_thread);
}
}
return ResultSuccess();
}
}