diff --git a/kernel/src/main.cpp b/kernel/src/main.cpp index 05768089..1a45e8b3 100644 --- a/kernel/src/main.cpp +++ b/kernel/src/main.cpp @@ -49,6 +49,7 @@ Result init() kinfoln("Used memory: %s", to_dynamic_unit(MemoryManager::used()).release_value().chars()); kinfoln("Reserved memory: %s", to_dynamic_unit(MemoryManager::reserved()).release_value().chars()); + Thread::init(); Scheduler::init(); TRY(Scheduler::new_kernel_thread(async_thread)); diff --git a/kernel/src/thread/Thread.cpp b/kernel/src/thread/Thread.cpp index 5f834d6e..48540869 100644 --- a/kernel/src/thread/Thread.cpp +++ b/kernel/src/thread/Thread.cpp @@ -1,10 +1,16 @@ #include "thread/Thread.h" #include +#include -static u64 g_next_id = 1; +static Atomic g_next_id; DoublyLinkedList g_threads; +void Thread::init() +{ + g_next_id = 1; +} + Result new_thread() { Thread* thread = TRY(make()); diff --git a/kernel/src/thread/Thread.h b/kernel/src/thread/Thread.h index 53e41a21..ad33d895 100644 --- a/kernel/src/thread/Thread.h +++ b/kernel/src/thread/Thread.h @@ -47,6 +47,8 @@ struct Thread : public DoublyLinkedListNode void set_sp(u64 sp); u64 sp(); + + static void init(); }; void switch_context(Thread* old_thread, Thread* new_thread, Registers* regs);