Kernel: Move current and idle thread to Processor

This commit is contained in:
2024-03-08 23:24:18 +02:00
parent e636dce919
commit 2420886c2c
5 changed files with 49 additions and 37 deletions

View File

@@ -5,6 +5,7 @@
#include <kernel/Arch.h>
#include <kernel/GDT.h>
#include <kernel/IDT.h>
#include <kernel/SchedulerQueue.h>
namespace Kernel
{
@@ -27,6 +28,7 @@ namespace Kernel
public:
static Processor& create(ProcessorID id);
static Processor& initialize();
static void allocate_idle_thread();
static ProcessorID current_id() { return read_gs_sized<ProcessorID>(offsetof(Processor, m_id)); }
@@ -62,6 +64,10 @@ namespace Kernel
static void* get_current_page_table() { return read_gs_ptr(offsetof(Processor, m_current_page_table)); }
static void set_current_page_table(void* page_table) { write_gs_ptr(offsetof(Processor, m_current_page_table), page_table); }
static Thread* idle_thread() { return reinterpret_cast<Thread*>(read_gs_ptr(offsetof(Processor, m_idle_thread))); }
static SchedulerQueue::Node* get_current_thread() { return reinterpret_cast<SchedulerQueue::Node*>(read_gs_ptr(offsetof(Processor, m_current_thread))); }
static void set_current_thread(SchedulerQueue::Node* thread) { write_gs_ptr(offsetof(Processor, m_current_thread), thread); }
private:
Processor() = default;
~Processor() { ASSERT_NOT_REACHED(); }
@@ -112,6 +118,9 @@ namespace Kernel
GDT* m_gdt { nullptr };
IDT* m_idt { nullptr };
Thread* m_idle_thread { nullptr };
SchedulerQueue::Node* m_current_thread { nullptr };
void* m_current_page_table { nullptr };
friend class BAN::Array<Processor, 0xFF>;

View File

@@ -38,7 +38,7 @@ namespace Kernel
private:
Scheduler() = default;
void set_current_thread_sleeping_impl(uint64_t wake_time);
void set_current_thread_sleeping_impl(Semaphore* semaphore, uint64_t wake_time);
[[nodiscard]] bool save_current_thread();
void advance_current_thread();
@@ -54,9 +54,6 @@ namespace Kernel
SchedulerQueue m_active_threads;
SchedulerQueue m_blocking_threads;
Thread* m_idle_thread { nullptr };
SchedulerQueue::Node* m_current_thread { nullptr };
friend class Process;
};