use core::cmp::Ordering; use alloc::vec; use alloc::vec::Vec; use crate::kmain::THREAD_LIST; pub type Pointer = fn(); pub type ThreadID = u64; pub type TaskID = u64; pub type ThreadList = Vec; #[derive(Eq, Debug)] pub struct Task { id: TaskID, parent_thread: ThreadID, fn_pointer: Pointer, } impl Task { fn new(parent_thread: ThreadID, task_id: u64, function_pointer: fn()) -> Self { Self { id: task_id, parent_thread, fn_pointer: function_pointer, } } } impl Ord for Task { fn cmp(&self, other: &Self) -> Ordering { self.id.cmp(&other.id) } } impl PartialOrd for Task { fn partial_cmp(&self, other: &Self) -> Option { Some(self.cmp(other)) } } impl PartialEq for Task { fn eq(&self, other: &Self) -> bool { self.id == other.id } } #[derive(Debug)] pub struct Thread { pub id: ThreadID, pub tasks: Vec, } impl Thread { pub fn new() -> Self { let threads = &*THREAD_LIST.lock(); let mut final_threadid = 0; match threads.last() { Some(last_thread) => final_threadid = last_thread.id + 1, None => {} } Self { id: final_threadid, tasks: vec![], } } pub fn sort_tasks(&mut self) { self.tasks.sort(); } pub fn new_task_id(&self) -> TaskID { self.tasks.len().try_into().unwrap() } pub fn new_task(&mut self, function_pointer: fn()) { let x = Task::new(self.id, self.new_task_id(), function_pointer); self.tasks.push(x); } } pub fn test_fn() { println!("Hello"); }