diff options
| author | 2019-03-16 00:43:09 -0400 | |
|---|---|---|
| committer | 2019-03-16 00:43:09 -0400 | |
| commit | bdf2da4ee811790014f900b165720c983dbf0b65 (patch) | |
| tree | ab2de1c608f4860af3d75863f9a5a766e09e6710 /src | |
| parent | Merge pull request #2237 from bunnei/cache-host-addr (diff) | |
| parent | kernel/thread: Move thread exiting logic from ExitCurrentThread to svcExitThread (diff) | |
| download | yuzu-bdf2da4ee811790014f900b165720c983dbf0b65.tar.gz yuzu-bdf2da4ee811790014f900b165720c983dbf0b65.tar.xz yuzu-bdf2da4ee811790014f900b165720c983dbf0b65.zip | |
Merge pull request #2242 from lioncash/thread-fn
kernel/thread: Remove WaitCurrentThread_Sleep() and ExitCurrentThread()
Diffstat (limited to '')
| -rw-r--r-- | src/core/hle/kernel/scheduler.cpp | 6 | ||||
| -rw-r--r-- | src/core/hle/kernel/svc.cpp | 32 | ||||
| -rw-r--r-- | src/core/hle/kernel/thread.cpp | 13 | ||||
| -rw-r--r-- | src/core/hle/kernel/thread.h | 13 |
4 files changed, 31 insertions, 33 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..047fa0c19 100644 --- a/src/core/hle/kernel/svc.cpp +++ b/src/core/hle/kernel/svc.cpp | |||
| @@ -1284,10 +1284,14 @@ static ResultCode StartThread(Handle thread_handle) { | |||
| 1284 | 1284 | ||
| 1285 | /// Called when a thread exits | 1285 | /// Called when a thread exits |
| 1286 | static void ExitThread() { | 1286 | static void ExitThread() { |
| 1287 | LOG_TRACE(Kernel_SVC, "called, pc=0x{:08X}", Core::CurrentArmInterface().GetPC()); | 1287 | auto& system = Core::System::GetInstance(); |
| 1288 | 1288 | ||
| 1289 | ExitCurrentThread(); | 1289 | LOG_TRACE(Kernel_SVC, "called, pc=0x{:08X}", system.CurrentArmInterface().GetPC()); |
| 1290 | Core::System::GetInstance().PrepareReschedule(); | 1290 | |
| 1291 | auto* const current_thread = system.CurrentScheduler().GetCurrentThread(); | ||
| 1292 | current_thread->Stop(); | ||
| 1293 | system.CurrentScheduler().RemoveThread(current_thread); | ||
| 1294 | system.PrepareReschedule(); | ||
| 1291 | } | 1295 | } |
| 1292 | 1296 | ||
| 1293 | /// Sleep the current thread | 1297 | /// Sleep the current thread |
| @@ -1300,32 +1304,32 @@ static void SleepThread(s64 nanoseconds) { | |||
| 1300 | YieldAndWaitForLoadBalancing = -2, | 1304 | YieldAndWaitForLoadBalancing = -2, |
| 1301 | }; | 1305 | }; |
| 1302 | 1306 | ||
| 1307 | auto& system = Core::System::GetInstance(); | ||
| 1308 | auto& scheduler = system.CurrentScheduler(); | ||
| 1309 | auto* const current_thread = scheduler.GetCurrentThread(); | ||
| 1310 | |||
| 1303 | if (nanoseconds <= 0) { | 1311 | if (nanoseconds <= 0) { |
| 1304 | auto& scheduler{Core::System::GetInstance().CurrentScheduler()}; | ||
| 1305 | switch (static_cast<SleepType>(nanoseconds)) { | 1312 | switch (static_cast<SleepType>(nanoseconds)) { |
| 1306 | case SleepType::YieldWithoutLoadBalancing: | 1313 | case SleepType::YieldWithoutLoadBalancing: |
| 1307 | scheduler.YieldWithoutLoadBalancing(GetCurrentThread()); | 1314 | scheduler.YieldWithoutLoadBalancing(current_thread); |
| 1308 | break; | 1315 | break; |
| 1309 | case SleepType::YieldWithLoadBalancing: | 1316 | case SleepType::YieldWithLoadBalancing: |
| 1310 | scheduler.YieldWithLoadBalancing(GetCurrentThread()); | 1317 | scheduler.YieldWithLoadBalancing(current_thread); |
| 1311 | break; | 1318 | break; |
| 1312 | case SleepType::YieldAndWaitForLoadBalancing: | 1319 | case SleepType::YieldAndWaitForLoadBalancing: |
| 1313 | scheduler.YieldAndWaitForLoadBalancing(GetCurrentThread()); | 1320 | scheduler.YieldAndWaitForLoadBalancing(current_thread); |
| 1314 | break; | 1321 | break; |
| 1315 | default: | 1322 | default: |
| 1316 | UNREACHABLE_MSG("Unimplemented sleep yield type '{:016X}'!", nanoseconds); | 1323 | UNREACHABLE_MSG("Unimplemented sleep yield type '{:016X}'!", nanoseconds); |
| 1317 | } | 1324 | } |
| 1318 | } else { | 1325 | } else { |
| 1319 | // Sleep current thread and check for next thread to schedule | 1326 | 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 | } | 1327 | } |
| 1325 | 1328 | ||
| 1326 | // Reschedule all CPU cores | 1329 | // Reschedule all CPU cores |
| 1327 | for (std::size_t i = 0; i < Core::NUM_CPU_CORES; ++i) | 1330 | for (std::size_t i = 0; i < Core::NUM_CPU_CORES; ++i) { |
| 1328 | Core::System::GetInstance().CpuCore(i).PrepareReschedule(); | 1331 | system.CpuCore(i).PrepareReschedule(); |
| 1332 | } | ||
| 1329 | } | 1333 | } |
| 1330 | 1334 | ||
| 1331 | /// Wait process wide key atomic | 1335 | /// 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..ccdefeecc 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; |
| @@ -460,14 +463,4 @@ private: | |||
| 460 | */ | 463 | */ |
| 461 | Thread* GetCurrentThread(); | 464 | Thread* GetCurrentThread(); |
| 462 | 465 | ||
| 463 | /** | ||
| 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 | ||
| 470 | */ | ||
| 471 | void ExitCurrentThread(); | ||
| 472 | |||
| 473 | } // namespace Kernel | 466 | } // namespace Kernel |