VERY experimental Nintendo Switch 2 emulator
C++
Kernel: Properly initialize and shutdown all modules.
bunneic7dc799e193d
diff --git a/src/core/hle/kernel/kernel.cpp b/src/core/hle/kernel/kernel.cppindex 6261b82b6f..fca582bbee 100644--- a/src/core/hle/kernel/kernel.cpp+++ b/src/core/hle/kernel/kernel.cpp@@ -14,11 +14,10 @@namespace Kernel {-unsigned int Object::next_object_id = 0;--SharedPtr<Thread> g_main_thread = nullptr;+unsigned int Object::next_object_id;+SharedPtr<Thread> g_main_thread;HandleTable g_handle_table;-u64 g_program_id = 0;+u64 g_program_id;void WaitObject::AddWaitingThread(SharedPtr<Thread> thread) {auto itr = std::find(waiting_threads.begin(), waiting_threads.end(), thread);@@ -138,6 +137,10 @@ void HandleTable::Clear() {void Init() {Kernel::ThreadingInit();Kernel::TimersInit();++ Object::next_object_id = 0;+ g_program_id = 0;+ g_main_thread = nullptr;}/// Shutdown the kerneldiff --git a/src/core/hle/kernel/kernel.h b/src/core/hle/kernel/kernel.hindex 2d295ea001..ab06fa025d 100644--- a/src/core/hle/kernel/kernel.h+++ b/src/core/hle/kernel/kernel.h@@ -95,12 +95,13 @@ public:return false;}+public:+ static unsigned int next_object_id;+private:friend void intrusive_ptr_add_ref(Object*);friend void intrusive_ptr_release(Object*);- static unsigned int next_object_id;-unsigned int ref_count = 0;unsigned int object_id = next_object_id++;};diff --git a/src/core/hle/kernel/thread.cpp b/src/core/hle/kernel/thread.cppindex 33d66b9867..d678f5f6fe 100644--- a/src/core/hle/kernel/thread.cpp+++ b/src/core/hle/kernel/thread.cpp@@ -23,7 +23,7 @@namespace Kernel {/// Event type for the thread wake up event-static int ThreadWakeupEventType = -1;+static int ThreadWakeupEventType;bool Thread::ShouldWait() {return status != THREADSTATUS_DEAD;@@ -42,7 +42,7 @@ static Common::ThreadQueueList<Thread*, THREADPRIO_LOWEST+1> ready_queue;static Thread* current_thread;// The first available thread id at startup-static u32 next_thread_id = 1;+static u32 next_thread_id;/*** Creates a new thread ID@@ -497,6 +497,12 @@ void Thread::SetWaitSynchronizationOutput(s32 output) {void ThreadingInit() {ThreadWakeupEventType = CoreTiming::RegisterEvent("ThreadWakeupCallback", ThreadWakeupCallback);+ current_thread = nullptr;+ next_thread_id = 1;++ thread_list.clear();+ ready_queue.clear();+// Setup the idle threadSetupIdleThread();}diff --git a/src/core/hle/kernel/timer.cpp b/src/core/hle/kernel/timer.cppindex 1ec2a4b109..36979248de 100644--- a/src/core/hle/kernel/timer.cpp+++ b/src/core/hle/kernel/timer.cpp@@ -12,7 +12,7 @@namespace Kernel {/// The event type of the generic timer callback event-static int timer_callback_event_type = -1;+static int timer_callback_event_type;// TODO(yuriks): This can be removed if Timer objects are explicitly pooled in the future, allowing// us to simply use a pool index or similar.static Kernel::HandleTable timer_callback_handle_table;@@ -89,6 +89,7 @@ static void TimerCallback(u64 timer_handle, int cycles_late) {}void TimersInit() {+ timer_callback_handle_table.Clear();timer_callback_event_type = CoreTiming::RegisterEvent("TimerCallback", TimerCallback);}