Implement domain and endpoint modules with capability management, message passing, and scheduling features
This commit is contained in:
52
crates/domain/src/scheduler/per_core.rs
Normal file
52
crates/domain/src/scheduler/per_core.rs
Normal file
@@ -0,0 +1,52 @@
|
||||
use super::priority_queue::PriorityQueue;
|
||||
use types::bounded::Priority;
|
||||
use types::id::{CoreId, ThreadId};
|
||||
|
||||
pub struct PerCoreScheduler {
|
||||
core: CoreId,
|
||||
queue: PriorityQueue,
|
||||
current: Option<ThreadId>,
|
||||
}
|
||||
|
||||
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<ThreadId> {
|
||||
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<ThreadId> {
|
||||
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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user