VERY experimental Nintendo Switch 2 emulator
C++
Thread: Modernize two functions that slipped through previous rebases
Yuri Kunde Schlesner664c79ff4705
diff --git a/src/core/hle/kernel/address_arbiter.cpp b/src/core/hle/kernel/address_arbiter.cppindex 2d01e2ef58..6e8f959f33 100644--- a/src/core/hle/kernel/address_arbiter.cpp+++ b/src/core/hle/kernel/address_arbiter.cpp@@ -51,7 +51,7 @@ ResultCode AddressArbiter::ArbitrateAddress(ArbitrationType type, VAddr address,case ArbitrationType::WaitIfLessThanWithTimeout:if ((s32)Memory::Read32(address) <= value) {Kernel::WaitCurrentThread_ArbitrateAddress(address);- Kernel::WakeThreadAfterDelay(GetCurrentThread(), nanoseconds);+ GetCurrentThread()->WakeAfterDelay(nanoseconds);HLE::Reschedule(__func__);}break;@@ -71,7 +71,7 @@ ResultCode AddressArbiter::ArbitrateAddress(ArbitrationType type, VAddr address,Memory::Write32(address, memory_value);if (memory_value <= value) {Kernel::WaitCurrentThread_ArbitrateAddress(address);- Kernel::WakeThreadAfterDelay(GetCurrentThread(), nanoseconds);+ GetCurrentThread()->WakeAfterDelay(nanoseconds);HLE::Reschedule(__func__);}break;diff --git a/src/core/hle/kernel/thread.cpp b/src/core/hle/kernel/thread.cppindex 56950ebd46..1ea5589cbb 100644--- a/src/core/hle/kernel/thread.cpp+++ b/src/core/hle/kernel/thread.cpp@@ -248,14 +248,13 @@ static void ThreadWakeupCallback(u64 parameter, int cycles_late) {}-void WakeThreadAfterDelay(Thread* thread, s64 nanoseconds) {+void Thread::WakeAfterDelay(s64 nanoseconds) {// Don't schedule a wakeup if the thread wants to wait foreverif (nanoseconds == -1)return;- _dbg_assert_(Kernel, thread != nullptr);u64 microseconds = nanoseconds / 1000;- CoreTiming::ScheduleEvent(usToCycles(microseconds), ThreadWakeupEventType, thread->GetHandle());+ CoreTiming::ScheduleEvent(usToCycles(microseconds), ThreadWakeupEventType, GetHandle());}void Thread::ReleaseWaitObject(WaitObject* wait_object) {@@ -418,7 +417,7 @@ void Thread::SetPriority(s32 priority) {}}-Handle SetupIdleThread() {+SharedPtr<Thread> SetupIdleThread() {// We need to pass a few valid values to get around parameter checking in Thread::Create.auto thread_res = Thread::Create("idle", Memory::KERNEL_MEMORY_VADDR, THREADPRIO_LOWEST, 0,THREADPROCESSORID_0, 0, Kernel::DEFAULT_STACK_SIZE);@@ -427,7 +426,7 @@ Handle SetupIdleThread() {thread->idle = true;CallThread(thread.get());- return thread->GetHandle();+ return thread;}SharedPtr<Thread> SetupMainThread(s32 priority, u32 stack_size) {diff --git a/src/core/hle/kernel/thread.h b/src/core/hle/kernel/thread.hindex d6299364ab..cba074e079 100644--- a/src/core/hle/kernel/thread.h+++ b/src/core/hle/kernel/thread.h@@ -77,6 +77,12 @@ public:/// Resumes a thread from waiting by marking it as "ready"void ResumeFromWait();+ /**+ * Schedules an event to wake up the specified thread after the specified delay.+ * @param nanoseconds The time this thread will be allowed to sleep for.+ */+ void WakeAfterDelay(s64 nanoseconds);+/*** Sets the result after the thread awakens (from either WaitSynchronization SVC)* @param result Value to set to the returned result@@ -150,20 +156,13 @@ void WaitCurrentThread_WaitSynchronization(SharedPtr<WaitObject> wait_object, bo*/void WaitCurrentThread_ArbitrateAddress(VAddr wait_address);-/**- * Schedules an event to wake up the specified thread after the specified delay.- * @param handle The thread handle.- * @param nanoseconds The time this thread will be allowed to sleep for.- */-void WakeThreadAfterDelay(Thread* thread, s64 nanoseconds);-/*** Sets up the idle thread, this is a thread that is intended to never execute instructions,* only to advance the timing. It is scheduled when there are no other ready threads in the thread queue* and will try to yield on every call.* @returns The handle of the idle thread*/-Handle SetupIdleThread();+SharedPtr<Thread> SetupIdleThread();/// Initialize threadingvoid ThreadingInit();diff --git a/src/core/hle/svc.cpp b/src/core/hle/svc.cppindex d253f4fe58..1a0c07cb9e 100644--- a/src/core/hle/svc.cpp+++ b/src/core/hle/svc.cpp@@ -152,7 +152,7 @@ static ResultCode WaitSynchronization1(Handle handle, s64 nano_seconds) {Kernel::WaitCurrentThread_WaitSynchronization(object, false, false);// Create an event to wake the thread up after the specified nanosecond delay has passed- Kernel::WakeThreadAfterDelay(Kernel::GetCurrentThread(), nano_seconds);+ Kernel::GetCurrentThread()->WakeAfterDelay(nano_seconds);HLE::Reschedule(__func__);@@ -228,7 +228,7 @@ static ResultCode WaitSynchronizationN(s32* out, Handle* handles, s32 handle_cou}// Create an event to wake the thread up after the specified nanosecond delay has passed- Kernel::WakeThreadAfterDelay(Kernel::GetCurrentThread(), nano_seconds);+ Kernel::GetCurrentThread()->WakeAfterDelay(nano_seconds);HLE::Reschedule(__func__);@@ -540,7 +540,7 @@ static void SleepThread(s64 nanoseconds) {Kernel::WaitCurrentThread_Sleep();// Create an event to wake the thread up after the specified nanosecond delay has passed- Kernel::WakeThreadAfterDelay(Kernel::GetCurrentThread(), nanoseconds);+ Kernel::GetCurrentThread()->WakeAfterDelay(nanoseconds);HLE::Reschedule(__func__);}