Thread: Make g_next_id atomic

This commit is contained in:
apio 2022-12-17 10:50:49 +01:00
parent 14461c6fe8
commit 6e5d2b5335
Signed by: apio
GPG Key ID: B8A7D06E42258954
3 changed files with 10 additions and 1 deletions

View File

@ -49,6 +49,7 @@ Result<void> init()
kinfoln("Used memory: %s", to_dynamic_unit(MemoryManager::used()).release_value().chars()); kinfoln("Used memory: %s", to_dynamic_unit(MemoryManager::used()).release_value().chars());
kinfoln("Reserved memory: %s", to_dynamic_unit(MemoryManager::reserved()).release_value().chars()); kinfoln("Reserved memory: %s", to_dynamic_unit(MemoryManager::reserved()).release_value().chars());
Thread::init();
Scheduler::init(); Scheduler::init();
TRY(Scheduler::new_kernel_thread(async_thread)); TRY(Scheduler::new_kernel_thread(async_thread));

View File

@ -1,10 +1,16 @@
#include "thread/Thread.h" #include "thread/Thread.h"
#include <luna/Alloc.h> #include <luna/Alloc.h>
#include <luna/Atomic.h>
static u64 g_next_id = 1; static Atomic<u64> g_next_id;
DoublyLinkedList<Thread> g_threads; DoublyLinkedList<Thread> g_threads;
void Thread::init()
{
g_next_id = 1;
}
Result<Thread*> new_thread() Result<Thread*> new_thread()
{ {
Thread* thread = TRY(make<Thread>()); Thread* thread = TRY(make<Thread>());

View File

@ -47,6 +47,8 @@ struct Thread : public DoublyLinkedListNode<Thread>
void set_sp(u64 sp); void set_sp(u64 sp);
u64 sp(); u64 sp();
static void init();
}; };
void switch_context(Thread* old_thread, Thread* new_thread, Registers* regs); void switch_context(Thread* old_thread, Thread* new_thread, Registers* regs);