Merge pull request #28 from bunnei/sleepthread

svc: Improve SleepThread for yield types.
This commit is contained in:
ReaperOfSouls
2018-11-24 20:46:01 -04:00
committed by GitHub

View File

@@ -947,12 +947,24 @@ static void ExitThread() {
/// Sleep the current thread
static void SleepThread(s64 nanoseconds) {
LOG_TRACE(Kernel_SVC, "called nanoseconds={}", nanoseconds);
LOG_DEBUG(Kernel_SVC, "called nanoseconds={}", nanoseconds);
// Don't attempt to yield execution if there are no available threads to run,
// this way we avoid a useless reschedule to the idle thread.
if (nanoseconds == 0 && !Core::System::GetInstance().CurrentScheduler().HaveReadyThreads())
if (nanoseconds == 0) {
// Yield type 0 is just a yield without load balancing
Core::System::GetInstance().CpuCore(0).PrepareReschedule();
Core::System::GetInstance().CpuCore(1).PrepareReschedule();
Core::System::GetInstance().CpuCore(2).PrepareReschedule();
Core::System::GetInstance().CpuCore(3).PrepareReschedule();
return;
}
if (nanoseconds < 0) {
UNIMPLEMENTED_MSG("unimplemented yield type");
// TODO(bunnei): Implement the various load balancing yield types here. This will force a
// reschedule, but is incorrect.
nanoseconds = 0;
}
// Sleep current thread and check for next thread to schedule
WaitCurrentThread_Sleep();
@@ -960,7 +972,10 @@ static void SleepThread(s64 nanoseconds) {
// Create an event to wake the thread up after the specified nanosecond delay has passed
GetCurrentThread()->WakeAfterDelay(nanoseconds);
Core::System::GetInstance().PrepareReschedule();
Core::System::GetInstance().CpuCore(0).PrepareReschedule();
Core::System::GetInstance().CpuCore(1).PrepareReschedule();
Core::System::GetInstance().CpuCore(2).PrepareReschedule();
Core::System::GetInstance().CpuCore(3).PrepareReschedule();
}
/// Wait process wide key atomic