![]() |
Max OS 0.3
|
Schedules processes to run on the core via their threads. More...
#include <scheduler.h>
Public Member Functions | |
| Scheduler () | |
| Constructs a new Scheduler object and creates the idle process. | |
| system::cpu_status_t * | schedule (system::cpu_status_t *cpu_state) |
| Schedules the next thread to run. | |
| system::cpu_status_t * | schedule_next (system::cpu_status_t *status) |
| Schedules the next thread to run. | |
| system::cpu_status_t * | yield () |
| Pass execution to the next thread. | |
| uint64_t | add_process (Process *process) |
| Adds a process to the scheduler. | |
| 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 stopped but the process is not removed (this will be done automatically when all threads are stopped) | |
| system::cpu_status_t * | force_remove_process (Process *process) |
| Removes a process from the scheduler and deletes all threads, begins running the next process. | |
| uint64_t | add_thread (Thread *thread) |
| Adds a thread to the scheduler. | |
| Process * | current_process () |
| Gets the current process. | |
| Process * | get_process (uint64_t pid) |
| Gets a process by its PID. | |
| uint64_t | process_amount () |
| Gets how processes are running on this scheduler. | |
| Thread * | current_thread () |
| Gets the currently executing thread. | |
| Thread * | get_thread (uint64_t tid) |
| Gets a thread by its TID. | |
| uint64_t | thread_amount () |
| Gets how many threads are running on this scheduler. | |
| uint64_t | ticks () const |
| Gets how long the system has been running for. | |
| void | activate () |
| Activates the scheduler. | |
| void | deactivate () |
| Deactivates the scheduler. | |
Schedules processes to run on the core via their threads.
Definition at line 85 of file scheduler.h.
| Scheduler::Scheduler | ( | ) |
Constructs a new Scheduler object and creates the idle process.
Definition at line 365 of file scheduler.cpp.
References add_process(), and MaxOS::memory::MemoryManager::s_kernel_memory_manager.
| void Scheduler::activate | ( | ) |
Activates the scheduler.
Definition at line 573 of file scheduler.cpp.
| uint64_t Scheduler::add_process | ( | Process * | process | ) |
Adds a process to the scheduler.
| process | The process to add |
Definition at line 505 of file scheduler.cpp.
References add_thread(), MaxOS::processes::GlobalScheduler::next_pid(), MaxOS::processes::Process::set_pid(), MaxOS::processes::Process::threads(), and MaxOS::processes::Thread::tid.
Referenced by MaxOS::processes::GlobalScheduler::add_process(), and Scheduler().
| uint64_t Scheduler::add_thread | ( | Thread * | thread | ) |
Adds a thread to the scheduler.
| thread | The thread to add |
Definition at line 527 of file scheduler.cpp.
References MaxOS::processes::GlobalScheduler::next_tid(), and MaxOS::processes::Thread::tid.
Referenced by add_process(), and MaxOS::processes::GlobalScheduler::add_thread().
| Process * Scheduler::current_process | ( | ) |
Gets the current process.
Definition at line 647 of file scheduler.cpp.
References current_process(), current_thread(), MaxOS::processes::Thread::parent_pid, and MaxOS::processes::Process::pid().
Referenced by MaxOS::processes::GlobalScheduler::current_process(), current_process(), and schedule_next().
| Thread * Scheduler::current_thread | ( | ) |
Gets the currently executing thread.
Definition at line 691 of file scheduler.cpp.
Referenced by current_process(), MaxOS::processes::GlobalScheduler::current_thread(), force_remove_process(), schedule(), schedule_next(), and yield().
| void Scheduler::deactivate | ( | ) |
Deactivates the scheduler.
Definition at line 707 of file scheduler.cpp.
| cpu_status_t * Scheduler::force_remove_process | ( | Process * | process | ) |
Removes a process from the scheduler and deletes all threads, begins running the next process.
| process | The process to remove |
Definition at line 619 of file scheduler.cpp.
References current_thread(), MaxOS::processes::Process::remove_thread(), schedule_next(), MaxOS::processes::Process::threads(), and MaxOS::processes::Thread::tid.
| Process * Scheduler::get_process | ( | uint64_t | pid | ) |
Gets a process by its PID.
| pid | The process ID |
Definition at line 667 of file scheduler.cpp.
References MaxOS::processes::Process::pid().
| Thread * Scheduler::get_thread | ( | uint64_t | tid | ) |
Gets a thread by its TID.
| tid | The thread ID |
Definition at line 718 of file scheduler.cpp.
References MaxOS::processes::Thread::tid.
| uint64_t Scheduler::process_amount | ( | ) |
Gets how processes are running on this scheduler.
Definition at line 682 of file scheduler.cpp.
Referenced by MaxOS::processes::GlobalScheduler::add_process().
| uint64_t Scheduler::remove_process | ( | Process * | process | ) |
Removes a process from the scheduler if the process has no threads, if it does then the threads are stopped but the process is not removed (this will be done automatically when all threads are stopped)
| process | The process to remove |
Definition at line 584 of file scheduler.cpp.
References MaxOS::processes::Thread::thread_state, and MaxOS::processes::Process::threads().
Referenced by schedule_next().
| cpu_status_t * Scheduler::schedule | ( | system::cpu_status_t * | cpu_state | ) |
Schedules the next thread to run.
| cpu_state | The current CPU state |
Definition at line 387 of file scheduler.cpp.
References current_thread(), schedule_next(), MaxOS::processes::Thread::ticks, and MaxOS::processes::TICKS_PER_EVENT.
Referenced by MaxOS::processes::GlobalScheduler::handle_interrupt().
| cpu_status_t * Scheduler::schedule_next | ( | system::cpu_status_t * | status | ) |
Schedules the next thread to run.
| status | The current CPU status of the thread |
Definition at line 416 of file scheduler.cpp.
References current_process(), current_thread(), MaxOS::processes::Thread::execution_state, remove_process(), MaxOS::processes::Process::remove_thread(), MaxOS::processes::Thread::save_sse_state(), MaxOS::processes::Thread::thread_state, MaxOS::processes::Process::threads(), MaxOS::processes::TICKS_PER_EVENT, and MaxOS::processes::Thread::wakeup_time.
Referenced by force_remove_process(), schedule(), and yield().
| uint64_t Scheduler::thread_amount | ( | ) |
Gets how many threads are running on this scheduler.
Definition at line 700 of file scheduler.cpp.
Referenced by MaxOS::processes::GlobalScheduler::add_thread().
| uint64_t Scheduler::ticks | ( | ) | const |
Gets how long the system has been running for.
Definition at line 545 of file scheduler.cpp.
| cpu_status_t * Scheduler::yield | ( | ) |
Pass execution to the next thread.
Definition at line 555 of file scheduler.cpp.
References current_thread(), MaxOS::processes::Thread::execution_state, schedule_next(), and MaxOS::processes::Thread::thread_state.
Referenced by MaxOS::processes::GlobalScheduler::yield().