6.3 KiB
title | summary |
---|---|
scheduler.h | the scheduler is responsible for switching between threads and controlling processes |
scheduler_processes_chunk_T
- struct
These chunks are a combination of static array and linked list.
They store the process_T pointer for each valid pid_t
.
Name | Type | Description |
---|---|---|
processes | process_T** | The array of process pointers |
processes_bitmap | bitmap_T(reference needed) | If a bit in this bitmap is set, the processes entry with the same index is valid |
num_free_pids | uint32_t | The amount of free slots in this chunk |
prev | scheduler_processes_chunk_T* | The previous chunk |
next | scheduler_processes_chunk_T* | The next chunk |
scheduler_T
- struct
Name | Type | Description |
---|---|---|
num_threads | uint32_t | Total amount of currently spawned threads |
num_processes | uint32_t | Total amount of currently spawned processes |
running_thread | thread_T* | A pointer to the currently running thread. |
processes | scheduler_processes_chunk_T* | The first processes store chunk |
blocked | bool | Set to true, while switching the context. Thread safety mechanism. |
initialized | bool | Set to true, if the scheduler is initialized and started. |
scheduler_init(boot_info)
- function (void)
Initializes the scheduler and performs a nx_scheduler_start
kernel syscall.
boot_info is needed in to spawn the kernels' main process.
After this function, the whole kernel is in scheduling mode.
scheduler_start(state)
- function (cpu_state_T*)
Creates and starts a thread from state.
It returns the result of a context switch, I forgot, why I did it like that.
This is basically the backend for the nx_scheduler_start
kernel syscall.
scheduler_is_initialized()
- function (bool)
Returns if the scheduler is initialized (and running) or not.
scheduler_dump_info(process, indent)
- function (void)
This recursively lists information(pid, name, threads) for all child processes of process. indent is used intern for the recursive calls and should be set to 0 initially.
scheduler_register_thread(thread)
- function (thread_T*)
Registers thread in the scheduler.
scheduler_pause_thread(thread)
- function (void)
Pauses thread, by removing it from the scheduling queue.
Potential Bug: if thread was the currently running thread, this could cause issues, because it's prev and next values are nulled.
scheduler_start_thread(thread)
- function (void)
Starts thread, by linking it into the scheduling queue.
scheduler_kill_thread(thread)
- function (void)
Pauses and unregisters thread.
scheduler_register_process(process)
- function (pid_t)
Reqisters process and returns its pid.
scheduler_kill_process(process)
- function (void)
Kills process and its threads and childs.
scheduler_get_process(pid)
- function (process_T*)
Returns the process_T
pointer that is associated with pid.
scheduler_get_current_thread()
- function (thread_T*)
Returns a pointer to the currently running thread.
scheduler_get_current_process()
- function (process_T*)
Returns a pointer to the currently running threads process.
scheduler_switch_context(state)
- function (cpu_state_T*)
Saves state in the running threads state value and increments their cpu_time value. Then it sets the next thread as the running thread and returns its state. This needs to be called from an interrupt handler, for the returned state to be loaded.