From 6e5d2b5335f6fce15115ff42ce6ca4c3b7beeaf6 Mon Sep 17 00:00:00 2001 From: apio Date: Sat, 17 Dec 2022 10:50:49 +0100 Subject: [PATCH] Thread: Make g_next_id atomic --- kernel/src/main.cpp | 1 + kernel/src/thread/Thread.cpp | 8 +++++++- kernel/src/thread/Thread.h | 2 ++ 3 files changed, 10 insertions(+), 1 deletion(-) 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);