1
0
Fork 0

Kernel: Properly initialize and shutdown all modules.

This commit is contained in:
bunnei 2015-04-27 22:12:35 -04:00
parent 57aaaf92db
commit c7dc799e19
4 changed files with 20 additions and 9 deletions

View File

@ -14,11 +14,10 @@
namespace Kernel { namespace Kernel {
unsigned int Object::next_object_id = 0; unsigned int Object::next_object_id;
SharedPtr<Thread> g_main_thread;
SharedPtr<Thread> g_main_thread = nullptr;
HandleTable g_handle_table; HandleTable g_handle_table;
u64 g_program_id = 0; u64 g_program_id;
void WaitObject::AddWaitingThread(SharedPtr<Thread> thread) { void WaitObject::AddWaitingThread(SharedPtr<Thread> thread) {
auto itr = std::find(waiting_threads.begin(), waiting_threads.end(), thread); auto itr = std::find(waiting_threads.begin(), waiting_threads.end(), thread);
@ -138,6 +137,10 @@ void HandleTable::Clear() {
void Init() { void Init() {
Kernel::ThreadingInit(); Kernel::ThreadingInit();
Kernel::TimersInit(); Kernel::TimersInit();
Object::next_object_id = 0;
g_program_id = 0;
g_main_thread = nullptr;
} }
/// Shutdown the kernel /// Shutdown the kernel

View File

@ -95,12 +95,13 @@ public:
return false; return false;
} }
public:
static unsigned int next_object_id;
private: private:
friend void intrusive_ptr_add_ref(Object*); friend void intrusive_ptr_add_ref(Object*);
friend void intrusive_ptr_release(Object*); friend void intrusive_ptr_release(Object*);
static unsigned int next_object_id;
unsigned int ref_count = 0; unsigned int ref_count = 0;
unsigned int object_id = next_object_id++; unsigned int object_id = next_object_id++;
}; };

View File

@ -23,7 +23,7 @@
namespace Kernel { namespace Kernel {
/// Event type for the thread wake up event /// Event type for the thread wake up event
static int ThreadWakeupEventType = -1; static int ThreadWakeupEventType;
bool Thread::ShouldWait() { bool Thread::ShouldWait() {
return status != THREADSTATUS_DEAD; return status != THREADSTATUS_DEAD;
@ -42,7 +42,7 @@ static Common::ThreadQueueList<Thread*, THREADPRIO_LOWEST+1> ready_queue;
static Thread* current_thread; static Thread* current_thread;
// The first available thread id at startup // The first available thread id at startup
static u32 next_thread_id = 1; static u32 next_thread_id;
/** /**
* Creates a new thread ID * Creates a new thread ID
@ -497,6 +497,12 @@ void Thread::SetWaitSynchronizationOutput(s32 output) {
void ThreadingInit() { void ThreadingInit() {
ThreadWakeupEventType = CoreTiming::RegisterEvent("ThreadWakeupCallback", ThreadWakeupCallback); ThreadWakeupEventType = CoreTiming::RegisterEvent("ThreadWakeupCallback", ThreadWakeupCallback);
current_thread = nullptr;
next_thread_id = 1;
thread_list.clear();
ready_queue.clear();
// Setup the idle thread // Setup the idle thread
SetupIdleThread(); SetupIdleThread();
} }

View File

@ -12,7 +12,7 @@
namespace Kernel { namespace Kernel {
/// The event type of the generic timer callback event /// 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 // 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. // us to simply use a pool index or similar.
static Kernel::HandleTable timer_callback_handle_table; static Kernel::HandleTable timer_callback_handle_table;
@ -89,6 +89,7 @@ static void TimerCallback(u64 timer_handle, int cycles_late) {
} }
void TimersInit() { void TimersInit() {
timer_callback_handle_table.Clear();
timer_callback_event_type = CoreTiming::RegisterEvent("TimerCallback", TimerCallback); timer_callback_event_type = CoreTiming::RegisterEvent("TimerCallback", TimerCallback);
} }