9#ifndef MAXOS_PROCESSES_SCHEDULER_H
10#define MAXOS_PROCESSES_SCHEDULER_H
20namespace MaxOS::processes {
30 bool m_active =
false;
91 uint64_t m_next_thread_index;
119 [[nodiscard]] uint64_t
ticks()
const;
Stores the left, top, width and height of a rectangle.
Enables a resource to be used by only one instance at a time through locking and unlocking.
Handles a certain interrupt number.
virtual void handle_interrupt()
Handles an interrupt.
Manages all the resource registries for each resource type.
The global scheduler that manages all processes and threads across all cores.
static uint64_t next_pid()
Gets the next usable global PID.
static Scheduler * core_scheduler()
Gets the scheduler for the currently executing core.
static Process * get_process(uint64_t pid)
Gets a process on the currently executing core by its PID.
static uint64_t remove_process(Process *process)
Removes a process from the scheduler if the process has no threads, if it does then the threads are s...
static system::cpu_status_t * yield(system::cpu_status_t *current)
Pass execution to the next thread.
static void print_running_header()
Print the header for the running processes in the form ({name}:t{tid}c{core})
static uint64_t next_tid()
Gets the next usable global TID.
~GlobalScheduler()
Destroys the global scheduler and frees the per core schedulers.
static GlobalScheduler * system_scheduler()
Gets the system scheduler.
static Process * current_process()
Gets the process on the currently executing core.
static Thread * get_thread(uint64_t tid)
Gets a thread on the currently executing core by its TID.
static void activate()
Activates each core's scheduler.
static void deactivate()
Deactivates each core's scheduler.
static bool is_active()
Checks if the global scheduler is active.
void balance()
Moves processes and threads between cores to balance the load so that each core has a similar amount ...
static Thread * current_thread()
Gets the thread on the currently executing core.
uint64_t add_process(Process *process)
Adds a process to the least busy core.
uint64_t add_thread(Thread *thread)
Adds a thread to the least busy core.
static void load_multiboot_elfs(system::Multiboot *multiboot)
Loads any valid ELF files from the multiboot structure.
static system::cpu_status_t * force_remove_process(Process *process)
Removes a process from the scheduler and deletes all threads, begins running the next process.
A process that can be scheduled by the Scheduler, wraps & manages threads as well as its own address ...
A resource registry for a specific resource type.
Schedules processes to run on the core via their threads.
uint64_t remove_process(Process *process)
Removes a process from the scheduler if the process has no threads, if it does then the threads are s...
uint64_t ticks() const
Gets how long the system has been running for.
Scheduler()
Constructs a new Scheduler object and creates the idle process.
uint64_t thread_amount()
Gets how many threads are running on this scheduler.
Thread * current_thread()
Gets the currently executing thread.
system::cpu_status_t * yield()
Pass execution to the next thread.
system::cpu_status_t * force_remove_process(Process *process)
Removes a process from the scheduler and deletes all threads, begins running the next process.
Process * get_process(uint64_t pid)
Gets a process by its PID.
uint64_t add_process(Process *process)
Adds a process to the scheduler.
Thread * get_thread(uint64_t tid)
Gets a thread by its TID.
uint64_t add_thread(Thread *thread)
Adds a thread to the scheduler.
system::cpu_status_t * schedule(system::cpu_status_t *cpu_state)
Schedules the next thread to run.
uint64_t process_amount()
Gets how processes are running on this scheduler.
void activate()
Activates the scheduler.
Process * current_process()
Gets the current process.
system::cpu_status_t * schedule_next(system::cpu_status_t *status)
Schedules the next thread to run.
void deactivate()
Deactivates the scheduler.
The execution context of a sub-process thread.
Parses and provides access to Multiboot 2 information.
Defines Central Processing Unit (CPU) structures and functions for managing CPU state and features.
struct PACKED MaxOS::system::CPUStatus cpu_status_t
Alias for CPUStatus struct.
Defines a InterruptManager and InterruptHandler for managing hardware and software interrupts.
Defines inter-process communication (IPC) methods such as shared memory and message endpoints.
Defines a MemoryManager class for handling memory allocation and deallocation.
Defines Process and Thread classes for managing processes and their execution contexts.
constexpr size_t TICKS_PER_EVENT
Number of times the clock has to interrupt before switching to the next process/thread.
Defines a Vector class for dynamically storing an array of elements.