use super::priority_queue::PriorityQueue; use types::bounded::Priority; use types::id::{CoreId, ThreadId}; pub struct PerCoreScheduler { core: CoreId, queue: PriorityQueue, current: Option, } impl PerCoreScheduler { pub fn new(core: CoreId) -> Self { Self { core, queue: PriorityQueue::new(), current: None, } } pub fn core(&self) -> CoreId { self.core } pub fn current(&self) -> Option { self.current } pub fn add(&mut self, thread: ThreadId, priority: Priority) { self.queue.add(thread, priority); } pub fn remove(&mut self, thread: ThreadId, priority: Priority) { self.queue.remove(thread, priority); } pub fn pick_next(&mut self) -> Option { let (thread, _priority) = self.queue.next()?; self.current = Some(thread); Some(thread) } pub fn clear_current(&mut self) { self.current = None; } pub fn len(&self) -> usize { // for load balancing — count of ready threads // could track this incrementally instead of computing // but for now, bitmap popcount works self.queue.bitmap().count_ones() as usize } }