mirror of
https://github.com/justinian/jsix.git
synced 2025-12-10 08:24:32 -08:00
[kernel] Add thead kobject class
Add the thread kernel API object and move the scheduler to use threads instead of processes for scheduling and task switching.
This commit is contained in:
@@ -3,15 +3,14 @@
|
||||
/// The task scheduler and related definitions
|
||||
|
||||
#include <stdint.h>
|
||||
#include "process.h"
|
||||
#include "objects/thread.h"
|
||||
|
||||
class lapic;
|
||||
struct page_table;
|
||||
struct cpu_state;
|
||||
|
||||
extern "C" void isr_handler(cpu_state*);
|
||||
extern "C" void task_switch(process *next);
|
||||
extern "C" void task_fork(process *child);
|
||||
extern "C" void task_switch(TCB *next);
|
||||
|
||||
|
||||
/// The task scheduler
|
||||
@@ -27,7 +26,7 @@ public:
|
||||
/// Default priority on process creation
|
||||
static const uint8_t default_priority = 1;
|
||||
|
||||
/// Loest (most urgent) priority achieved via promotion
|
||||
/// Lowest (most urgent) priority achieved via promotion
|
||||
static const uint8_t promote_limit = 1;
|
||||
|
||||
/// How long the base timer quantum is, in us
|
||||
@@ -50,15 +49,13 @@ public:
|
||||
void load_process(const char *name, const void *data, size_t size);
|
||||
|
||||
/// Create a new kernel task
|
||||
/// \arg pid Pid to use for this task, must be negative
|
||||
/// \arg proc Function to run as a kernel task
|
||||
/// \arg priority Priority to start the process with
|
||||
/// \arg flags Flags to add to the process
|
||||
/// \arg constant True if this task cannot be promoted/demoted
|
||||
void create_kernel_task(
|
||||
pid_t pid,
|
||||
void (*task)(),
|
||||
uint8_t priority,
|
||||
process_flags flags = process_flags::none);
|
||||
bool constant = false);
|
||||
|
||||
/// Get the quantum for a given priority.
|
||||
uint32_t quantum(int priority);
|
||||
@@ -70,14 +67,16 @@ public:
|
||||
/// Run the scheduler, possibly switching to a new task
|
||||
void schedule();
|
||||
|
||||
/// Get the current process.
|
||||
/// \returns A pointer to the current process' process struct
|
||||
inline process * current() { return m_current; }
|
||||
/// Get the current TCB.
|
||||
/// \returns A pointer to the current thread's TCB
|
||||
inline TCB * current() { return m_current; }
|
||||
|
||||
/*
|
||||
/// Look up a process by its PID
|
||||
/// \arg pid The requested PID
|
||||
/// \returns The process matching that PID, or nullptr
|
||||
process_node * get_process_by_id(uint32_t pid);
|
||||
tcb_node * get_process_by_id(uint32_t pid);
|
||||
*/
|
||||
|
||||
/// Get a reference to the system scheduler
|
||||
/// \returns A reference to the global system scheduler
|
||||
@@ -89,9 +88,9 @@ private:
|
||||
|
||||
/// Create a new process object. This process will have its pid
|
||||
/// set but nothing else.
|
||||
/// \arg pid The pid to give the process (0 for automatic)
|
||||
/// \returns The new process object
|
||||
process_node * create_process(pid_t pid = 0);
|
||||
/// \arg pml4 The root page table of the process
|
||||
/// \returns The new process' main thread
|
||||
thread * create_process(page_table *pml4);
|
||||
|
||||
void prune(uint64_t now);
|
||||
|
||||
@@ -100,10 +99,10 @@ private:
|
||||
uint32_t m_next_pid;
|
||||
uint32_t m_tick_count;
|
||||
|
||||
process_node *m_current;
|
||||
process_list m_runlists[num_priorities];
|
||||
process_list m_blocked;
|
||||
process_list m_exited;
|
||||
tcb_node *m_current;
|
||||
tcb_list m_runlists[num_priorities];
|
||||
tcb_list m_blocked;
|
||||
tcb_list m_exited;
|
||||
|
||||
// TODO: lol a real clock
|
||||
uint64_t m_clock = 0;
|
||||
|
||||
Reference in New Issue
Block a user