2023-03-10 10:32:50 +00:00
|
|
|
// This file is part of noxos and licensed under the MIT open source license
|
2023-02-18 21:10:27 +00:00
|
|
|
|
|
|
|
#ifndef NOX_SCHEDULER_H
|
|
|
|
#define NOX_SCHEDULER_H
|
|
|
|
|
|
|
|
#include "proc/thread.h"
|
2023-03-03 19:23:19 +00:00
|
|
|
#include "proc/process.h"
|
2023-02-18 21:10:27 +00:00
|
|
|
#include "utils/bitmap.h"
|
2023-03-04 16:46:21 +00:00
|
|
|
#include "boot/boot_info.h"
|
2023-02-18 21:10:27 +00:00
|
|
|
|
2023-03-03 19:23:19 +00:00
|
|
|
#define SCHEDULER_PROCESS_CHUNK_SIZE 64
|
|
|
|
|
|
|
|
typedef struct scheduler_processes_chunk_T scheduler_processes_chunk_T;
|
|
|
|
struct scheduler_processes_chunk_T {
|
|
|
|
process_T** processes;
|
|
|
|
bitmap_T processes_bitmap;
|
|
|
|
|
|
|
|
uint32_t num_free_pids;
|
|
|
|
|
|
|
|
scheduler_processes_chunk_T* prev;
|
|
|
|
scheduler_processes_chunk_T* next;
|
|
|
|
};
|
|
|
|
|
2023-02-18 21:10:27 +00:00
|
|
|
typedef struct {
|
2023-03-03 19:23:19 +00:00
|
|
|
uint32_t num_threads;
|
|
|
|
uint32_t num_processes;
|
|
|
|
thread_T* running_thread;
|
|
|
|
scheduler_processes_chunk_T* processes;
|
2023-02-18 21:10:27 +00:00
|
|
|
|
2023-03-03 19:23:19 +00:00
|
|
|
bool blocked;
|
|
|
|
bool initialized;
|
2023-02-18 21:10:27 +00:00
|
|
|
} scheduler_T;
|
|
|
|
|
2023-03-04 16:46:21 +00:00
|
|
|
void scheduler_init (boot_info_T* boot_info);
|
2023-03-03 19:23:19 +00:00
|
|
|
cpu_state_T* scheduler_start (cpu_state_T* state);
|
|
|
|
bool scheduler_is_initialized ();
|
2023-03-03 22:51:24 +00:00
|
|
|
void scheduler_dump_info (process_T* process, uint8_t indent);
|
2023-03-03 19:23:19 +00:00
|
|
|
|
|
|
|
thread_T* scheduler_register_thread (thread_T* thread);
|
|
|
|
void scheduler_pause_thread (thread_T* thread);
|
|
|
|
void scheduler_start_thread (thread_T* thread);
|
|
|
|
void scheduler_kill_thread (thread_T* thread);
|
2023-02-18 21:10:27 +00:00
|
|
|
|
2023-03-03 19:23:19 +00:00
|
|
|
pid_t scheduler_register_process (process_T* process);
|
2023-04-27 10:27:12 +00:00
|
|
|
void scheduler_pause_process (process_T* process);
|
|
|
|
void scheduler_start_process (process_T* process);
|
2023-03-03 19:23:19 +00:00
|
|
|
void scheduler_kill_process (process_T* process);
|
|
|
|
process_T* scheduler_get_process (pid_t pid);
|
2023-02-18 21:10:27 +00:00
|
|
|
|
2023-03-03 19:23:19 +00:00
|
|
|
thread_T* scheduler_get_current_thread ();
|
|
|
|
process_T* scheduler_get_current_process ();
|
2023-02-18 21:10:27 +00:00
|
|
|
|
2023-03-03 19:23:19 +00:00
|
|
|
cpu_state_T* scheduler_switch_context (cpu_state_T* state);
|
2023-02-18 21:10:27 +00:00
|
|
|
|
|
|
|
#endif //NOX_SCHEDULER_H
|