mirror of
https://github.com/yuzu-emu/yuzu.git
synced 2024-12-26 04:30:05 +00:00
Merge pull request #2242 from lioncash/thread-fn
kernel/thread: Remove WaitCurrentThread_Sleep() and ExitCurrentThread()
This commit is contained in:
commit
bdf2da4ee8
@ -199,8 +199,7 @@ void Scheduler::YieldWithoutLoadBalancing(Thread* thread) {
|
|||||||
ASSERT(thread->GetPriority() < THREADPRIO_COUNT);
|
ASSERT(thread->GetPriority() < THREADPRIO_COUNT);
|
||||||
|
|
||||||
// Yield this thread -- sleep for zero time and force reschedule to different thread
|
// Yield this thread -- sleep for zero time and force reschedule to different thread
|
||||||
WaitCurrentThread_Sleep();
|
GetCurrentThread()->Sleep(0);
|
||||||
GetCurrentThread()->WakeAfterDelay(0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Scheduler::YieldWithLoadBalancing(Thread* thread) {
|
void Scheduler::YieldWithLoadBalancing(Thread* thread) {
|
||||||
@ -215,8 +214,7 @@ void Scheduler::YieldWithLoadBalancing(Thread* thread) {
|
|||||||
ASSERT(priority < THREADPRIO_COUNT);
|
ASSERT(priority < THREADPRIO_COUNT);
|
||||||
|
|
||||||
// Sleep for zero time to be able to force reschedule to different thread
|
// Sleep for zero time to be able to force reschedule to different thread
|
||||||
WaitCurrentThread_Sleep();
|
GetCurrentThread()->Sleep(0);
|
||||||
GetCurrentThread()->WakeAfterDelay(0);
|
|
||||||
|
|
||||||
Thread* suggested_thread = nullptr;
|
Thread* suggested_thread = nullptr;
|
||||||
|
|
||||||
|
@ -1284,10 +1284,14 @@ static ResultCode StartThread(Handle thread_handle) {
|
|||||||
|
|
||||||
/// Called when a thread exits
|
/// Called when a thread exits
|
||||||
static void ExitThread() {
|
static void ExitThread() {
|
||||||
LOG_TRACE(Kernel_SVC, "called, pc=0x{:08X}", Core::CurrentArmInterface().GetPC());
|
auto& system = Core::System::GetInstance();
|
||||||
|
|
||||||
ExitCurrentThread();
|
LOG_TRACE(Kernel_SVC, "called, pc=0x{:08X}", system.CurrentArmInterface().GetPC());
|
||||||
Core::System::GetInstance().PrepareReschedule();
|
|
||||||
|
auto* const current_thread = system.CurrentScheduler().GetCurrentThread();
|
||||||
|
current_thread->Stop();
|
||||||
|
system.CurrentScheduler().RemoveThread(current_thread);
|
||||||
|
system.PrepareReschedule();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sleep the current thread
|
/// Sleep the current thread
|
||||||
@ -1300,32 +1304,32 @@ static void SleepThread(s64 nanoseconds) {
|
|||||||
YieldAndWaitForLoadBalancing = -2,
|
YieldAndWaitForLoadBalancing = -2,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
auto& system = Core::System::GetInstance();
|
||||||
|
auto& scheduler = system.CurrentScheduler();
|
||||||
|
auto* const current_thread = scheduler.GetCurrentThread();
|
||||||
|
|
||||||
if (nanoseconds <= 0) {
|
if (nanoseconds <= 0) {
|
||||||
auto& scheduler{Core::System::GetInstance().CurrentScheduler()};
|
|
||||||
switch (static_cast<SleepType>(nanoseconds)) {
|
switch (static_cast<SleepType>(nanoseconds)) {
|
||||||
case SleepType::YieldWithoutLoadBalancing:
|
case SleepType::YieldWithoutLoadBalancing:
|
||||||
scheduler.YieldWithoutLoadBalancing(GetCurrentThread());
|
scheduler.YieldWithoutLoadBalancing(current_thread);
|
||||||
break;
|
break;
|
||||||
case SleepType::YieldWithLoadBalancing:
|
case SleepType::YieldWithLoadBalancing:
|
||||||
scheduler.YieldWithLoadBalancing(GetCurrentThread());
|
scheduler.YieldWithLoadBalancing(current_thread);
|
||||||
break;
|
break;
|
||||||
case SleepType::YieldAndWaitForLoadBalancing:
|
case SleepType::YieldAndWaitForLoadBalancing:
|
||||||
scheduler.YieldAndWaitForLoadBalancing(GetCurrentThread());
|
scheduler.YieldAndWaitForLoadBalancing(current_thread);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
UNREACHABLE_MSG("Unimplemented sleep yield type '{:016X}'!", nanoseconds);
|
UNREACHABLE_MSG("Unimplemented sleep yield type '{:016X}'!", nanoseconds);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Sleep current thread and check for next thread to schedule
|
current_thread->Sleep(nanoseconds);
|
||||||
WaitCurrentThread_Sleep();
|
|
||||||
|
|
||||||
// Create an event to wake the thread up after the specified nanosecond delay has passed
|
|
||||||
GetCurrentThread()->WakeAfterDelay(nanoseconds);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reschedule all CPU cores
|
// Reschedule all CPU cores
|
||||||
for (std::size_t i = 0; i < Core::NUM_CPU_CORES; ++i)
|
for (std::size_t i = 0; i < Core::NUM_CPU_CORES; ++i) {
|
||||||
Core::System::GetInstance().CpuCore(i).PrepareReschedule();
|
system.CpuCore(i).PrepareReschedule();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Wait process wide key atomic
|
/// Wait process wide key atomic
|
||||||
|
@ -68,11 +68,6 @@ void Thread::Stop() {
|
|||||||
owner_process->FreeTLSSlot(tls_address);
|
owner_process->FreeTLSSlot(tls_address);
|
||||||
}
|
}
|
||||||
|
|
||||||
void WaitCurrentThread_Sleep() {
|
|
||||||
Thread* thread = GetCurrentThread();
|
|
||||||
thread->SetStatus(ThreadStatus::WaitSleep);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ExitCurrentThread() {
|
void ExitCurrentThread() {
|
||||||
Thread* thread = GetCurrentThread();
|
Thread* thread = GetCurrentThread();
|
||||||
thread->Stop();
|
thread->Stop();
|
||||||
@ -391,6 +386,14 @@ void Thread::SetActivity(ThreadActivity value) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Thread::Sleep(s64 nanoseconds) {
|
||||||
|
// Sleep current thread and check for next thread to schedule
|
||||||
|
SetStatus(ThreadStatus::WaitSleep);
|
||||||
|
|
||||||
|
// Create an event to wake the thread up after the specified nanosecond delay has passed
|
||||||
|
WakeAfterDelay(nanoseconds);
|
||||||
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -383,6 +383,9 @@ public:
|
|||||||
|
|
||||||
void SetActivity(ThreadActivity value);
|
void SetActivity(ThreadActivity value);
|
||||||
|
|
||||||
|
/// Sleeps this thread for the given amount of nanoseconds.
|
||||||
|
void Sleep(s64 nanoseconds);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
explicit Thread(KernelCore& kernel);
|
explicit Thread(KernelCore& kernel);
|
||||||
~Thread() override;
|
~Thread() override;
|
||||||
@ -460,14 +463,4 @@ private:
|
|||||||
*/
|
*/
|
||||||
Thread* GetCurrentThread();
|
Thread* GetCurrentThread();
|
||||||
|
|
||||||
/**
|
|
||||||
* Waits the current thread on a sleep
|
|
||||||
*/
|
|
||||||
void WaitCurrentThread_Sleep();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Stops the current thread and removes it from the thread_list
|
|
||||||
*/
|
|
||||||
void ExitCurrentThread();
|
|
||||||
|
|
||||||
} // namespace Kernel
|
} // namespace Kernel
|
||||||
|
Loading…
Reference in New Issue
Block a user