diff options
| -rw-r--r-- | src/core/hle/kernel/scheduler.cpp | 6 | ||||
| -rw-r--r-- | src/core/hle/kernel/svc.cpp | 22 | ||||
| -rw-r--r-- | src/core/hle/kernel/thread.cpp | 13 | ||||
| -rw-r--r-- | src/core/hle/kernel/thread.h | 8 |
4 files changed, 24 insertions, 25 deletions
diff --git a/src/core/hle/kernel/scheduler.cpp b/src/core/hle/kernel/scheduler.cpp index 5fccfd9f4..e524509df 100644 --- a/src/core/hle/kernel/scheduler.cpp +++ b/src/core/hle/kernel/scheduler.cpp | |||
| @@ -199,8 +199,7 @@ void Scheduler::YieldWithoutLoadBalancing(Thread* thread) { | |||
| 199 | ASSERT(thread->GetPriority() < THREADPRIO_COUNT); | 199 | ASSERT(thread->GetPriority() < THREADPRIO_COUNT); |
| 200 | 200 | ||
| 201 | // Yield this thread -- sleep for zero time and force reschedule to different thread | 201 | // Yield this thread -- sleep for zero time and force reschedule to different thread |
| 202 | WaitCurrentThread_Sleep(); | 202 | GetCurrentThread()->Sleep(0); |
| 203 | GetCurrentThread()->WakeAfterDelay(0); | ||
| 204 | } | 203 | } |
| 205 | 204 | ||
| 206 | void Scheduler::YieldWithLoadBalancing(Thread* thread) { | 205 | void Scheduler::YieldWithLoadBalancing(Thread* thread) { |
| @@ -215,8 +214,7 @@ void Scheduler::YieldWithLoadBalancing(Thread* thread) { | |||
| 215 | ASSERT(priority < THREADPRIO_COUNT); | 214 | ASSERT(priority < THREADPRIO_COUNT); |
| 216 | 215 | ||
| 217 | // Sleep for zero time to be able to force reschedule to different thread | 216 | // Sleep for zero time to be able to force reschedule to different thread |
| 218 | WaitCurrentThread_Sleep(); | 217 | GetCurrentThread()->Sleep(0); |
| 219 | GetCurrentThread()->WakeAfterDelay(0); | ||
| 220 | 218 | ||
| 221 | Thread* suggested_thread = nullptr; | 219 | Thread* suggested_thread = nullptr; |
| 222 | 220 | ||
diff --git a/src/core/hle/kernel/svc.cpp b/src/core/hle/kernel/svc.cpp index 77d0e3d96..bf77ce137 100644 --- a/src/core/hle/kernel/svc.cpp +++ b/src/core/hle/kernel/svc.cpp | |||
| @@ -1300,32 +1300,32 @@ static void SleepThread(s64 nanoseconds) { | |||
| 1300 | YieldAndWaitForLoadBalancing = -2, | 1300 | YieldAndWaitForLoadBalancing = -2, |
| 1301 | }; | 1301 | }; |
| 1302 | 1302 | ||
| 1303 | auto& system = Core::System::GetInstance(); | ||
| 1304 | auto& scheduler = system.CurrentScheduler(); | ||
| 1305 | auto* const current_thread = scheduler.GetCurrentThread(); | ||
| 1306 | |||
| 1303 | if (nanoseconds <= 0) { | 1307 | if (nanoseconds <= 0) { |
| 1304 | auto& scheduler{Core::System::GetInstance().CurrentScheduler()}; | ||
| 1305 | switch (static_cast<SleepType>(nanoseconds)) { | 1308 | switch (static_cast<SleepType>(nanoseconds)) { |
| 1306 | case SleepType::YieldWithoutLoadBalancing: | 1309 | case SleepType::YieldWithoutLoadBalancing: |
| 1307 | scheduler.YieldWithoutLoadBalancing(GetCurrentThread()); | 1310 | scheduler.YieldWithoutLoadBalancing(current_thread); |
| 1308 | break; | 1311 | break; |
| 1309 | case SleepType::YieldWithLoadBalancing: | 1312 | case SleepType::YieldWithLoadBalancing: |
| 1310 | scheduler.YieldWithLoadBalancing(GetCurrentThread()); | 1313 | scheduler.YieldWithLoadBalancing(current_thread); |
| 1311 | break; | 1314 | break; |
| 1312 | case SleepType::YieldAndWaitForLoadBalancing: | 1315 | case SleepType::YieldAndWaitForLoadBalancing: |
| 1313 | scheduler.YieldAndWaitForLoadBalancing(GetCurrentThread()); | 1316 | scheduler.YieldAndWaitForLoadBalancing(current_thread); |
| 1314 | break; | 1317 | break; |
| 1315 | default: | 1318 | default: |
| 1316 | UNREACHABLE_MSG("Unimplemented sleep yield type '{:016X}'!", nanoseconds); | 1319 | UNREACHABLE_MSG("Unimplemented sleep yield type '{:016X}'!", nanoseconds); |
| 1317 | } | 1320 | } |
| 1318 | } else { | 1321 | } else { |
| 1319 | // Sleep current thread and check for next thread to schedule | 1322 | current_thread->Sleep(nanoseconds); |
| 1320 | WaitCurrentThread_Sleep(); | ||
| 1321 | |||
| 1322 | // Create an event to wake the thread up after the specified nanosecond delay has passed | ||
| 1323 | GetCurrentThread()->WakeAfterDelay(nanoseconds); | ||
| 1324 | } | 1323 | } |
| 1325 | 1324 | ||
| 1326 | // Reschedule all CPU cores | 1325 | // Reschedule all CPU cores |
| 1327 | for (std::size_t i = 0; i < Core::NUM_CPU_CORES; ++i) | 1326 | for (std::size_t i = 0; i < Core::NUM_CPU_CORES; ++i) { |
| 1328 | Core::System::GetInstance().CpuCore(i).PrepareReschedule(); | 1327 | system.CpuCore(i).PrepareReschedule(); |
| 1328 | } | ||
| 1329 | } | 1329 | } |
| 1330 | 1330 | ||
| 1331 | /// Wait process wide key atomic | 1331 | /// Wait process wide key atomic |
diff --git a/src/core/hle/kernel/thread.cpp b/src/core/hle/kernel/thread.cpp index eb54d6651..2e712c9cb 100644 --- a/src/core/hle/kernel/thread.cpp +++ b/src/core/hle/kernel/thread.cpp | |||
| @@ -68,11 +68,6 @@ void Thread::Stop() { | |||
| 68 | owner_process->FreeTLSSlot(tls_address); | 68 | owner_process->FreeTLSSlot(tls_address); |
| 69 | } | 69 | } |
| 70 | 70 | ||
| 71 | void WaitCurrentThread_Sleep() { | ||
| 72 | Thread* thread = GetCurrentThread(); | ||
| 73 | thread->SetStatus(ThreadStatus::WaitSleep); | ||
| 74 | } | ||
| 75 | |||
| 76 | void ExitCurrentThread() { | 71 | void ExitCurrentThread() { |
| 77 | Thread* thread = GetCurrentThread(); | 72 | Thread* thread = GetCurrentThread(); |
| 78 | thread->Stop(); | 73 | thread->Stop(); |
| @@ -391,6 +386,14 @@ void Thread::SetActivity(ThreadActivity value) { | |||
| 391 | } | 386 | } |
| 392 | } | 387 | } |
| 393 | 388 | ||
| 389 | void Thread::Sleep(s64 nanoseconds) { | ||
| 390 | // Sleep current thread and check for next thread to schedule | ||
| 391 | SetStatus(ThreadStatus::WaitSleep); | ||
| 392 | |||
| 393 | // Create an event to wake the thread up after the specified nanosecond delay has passed | ||
| 394 | WakeAfterDelay(nanoseconds); | ||
| 395 | } | ||
| 396 | |||
| 394 | //////////////////////////////////////////////////////////////////////////////////////////////////// | 397 | //////////////////////////////////////////////////////////////////////////////////////////////////// |
| 395 | 398 | ||
| 396 | /** | 399 | /** |
diff --git a/src/core/hle/kernel/thread.h b/src/core/hle/kernel/thread.h index c48b21aba..d7c7a31f7 100644 --- a/src/core/hle/kernel/thread.h +++ b/src/core/hle/kernel/thread.h | |||
| @@ -383,6 +383,9 @@ public: | |||
| 383 | 383 | ||
| 384 | void SetActivity(ThreadActivity value); | 384 | void SetActivity(ThreadActivity value); |
| 385 | 385 | ||
| 386 | /// Sleeps this thread for the given amount of nanoseconds. | ||
| 387 | void Sleep(s64 nanoseconds); | ||
| 388 | |||
| 386 | private: | 389 | private: |
| 387 | explicit Thread(KernelCore& kernel); | 390 | explicit Thread(KernelCore& kernel); |
| 388 | ~Thread() override; | 391 | ~Thread() override; |
| @@ -461,11 +464,6 @@ private: | |||
| 461 | Thread* GetCurrentThread(); | 464 | Thread* GetCurrentThread(); |
| 462 | 465 | ||
| 463 | /** | 466 | /** |
| 464 | * Waits the current thread on a sleep | ||
| 465 | */ | ||
| 466 | void WaitCurrentThread_Sleep(); | ||
| 467 | |||
| 468 | /** | ||
| 469 | * Stops the current thread and removes it from the thread_list | 467 | * Stops the current thread and removes it from the thread_list |
| 470 | */ | 468 | */ |
| 471 | void ExitCurrentThread(); | 469 | void ExitCurrentThread(); |