diff options
author | Tom <tomut@yahoo.com> | 2020-06-28 15:34:31 -0600 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-07-01 12:07:01 +0200 |
commit | 16783bd14d5284542205a50c441562c19174f101 (patch) | |
tree | 433c7802b5d8dcb0d2bfe0da8f25dbc5145d6ddf /Kernel/Arch/i386/CPU.h | |
parent | cdc78515b6e12f6bf8b62cf311d8dde12e191cbd (diff) | |
download | serenity-16783bd14d5284542205a50c441562c19174f101.zip |
Kernel: Turn Thread::current and Process::current into functions
This allows us to query the current thread and process on a
per processor basis
Diffstat (limited to 'Kernel/Arch/i386/CPU.h')
-rw-r--r-- | Kernel/Arch/i386/CPU.h | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/Kernel/Arch/i386/CPU.h b/Kernel/Arch/i386/CPU.h index a19285f396..e1840e1a0c 100644 --- a/Kernel/Arch/i386/CPU.h +++ b/Kernel/Arch/i386/CPU.h @@ -626,6 +626,8 @@ class Processor { static FPUState s_clean_fpu_state; ProcessorInfo* m_info; + Thread* m_current_thread; + Thread* m_idle_thread; bool m_invoke_scheduler_async; @@ -661,6 +663,33 @@ public: return *(Processor*)read_fs_u32(0); } + ALWAYS_INLINE static bool is_initialized() + { + return get_fs() == GDT_SELECTOR_PROC && read_fs_u32(0) != 0; + } + + ALWAYS_INLINE Thread* idle_thread() const + { + return m_idle_thread; + } + + ALWAYS_INLINE void set_idle_thread(Thread& idle_thread) + { + m_idle_thread = &idle_thread; + } + + ALWAYS_INLINE Thread* current_thread() const + { + // NOTE: NOT safe to call from another processor! + ASSERT(&Processor::current() == this); + return m_current_thread; + } + + ALWAYS_INLINE void set_current_thread(Thread& current_thread) + { + m_current_thread = ¤t_thread; + } + ALWAYS_INLINE u32 id() { return m_cpu; |