#pragma once #include #include #include "object/process.h" #include "object/thread.h" class Scheduler { public: // Initializes the scheduler in a disabled state. // // Requires the process manager to have been initialized. static void Init(); void Enable() { enabled_ = true; } Process& CurrentProcess() { return current_thread_->process(); } glcr::RefPtr CurrentThread() { return current_thread_; } void Enqueue(const glcr::RefPtr& thread); void Preempt(); void Yield(); private: bool enabled_ = false; glcr::RefPtr current_thread_; glcr::IntrusiveList runnable_threads_; glcr::RefPtr sleep_thread_; Scheduler(); void SwapToCurrent(Thread& prev); void ClearDeadThreadsFromFront(); }; extern Scheduler* gScheduler;