adjustments on capabilities on cartridges
This commit is contained in:
@@ -28,7 +28,9 @@ struct SleepEntry {
|
||||
}
|
||||
|
||||
impl Scheduler {
|
||||
pub fn new() -> Self { Self::default() }
|
||||
pub fn new() -> Self {
|
||||
Self::default()
|
||||
}
|
||||
|
||||
// ---------- Ready queue operations ----------
|
||||
|
||||
@@ -43,15 +45,25 @@ impl Scheduler {
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
pub fn is_ready_empty(&self) -> bool { self.ready_queue.is_empty() }
|
||||
pub fn is_ready_empty(&self) -> bool {
|
||||
self.ready_queue.is_empty()
|
||||
}
|
||||
#[cfg(test)]
|
||||
pub fn ready_len(&self) -> usize { self.ready_queue.len() }
|
||||
pub fn ready_len(&self) -> usize {
|
||||
self.ready_queue.len()
|
||||
}
|
||||
|
||||
// ---------- Current tracking (no switching here) ----------
|
||||
pub fn set_current(&mut self, coro: Option<HeapRef>) { self.current = coro; }
|
||||
pub fn set_current(&mut self, coro: Option<HeapRef>) {
|
||||
self.current = coro;
|
||||
}
|
||||
#[cfg(test)]
|
||||
pub fn current(&self) -> Option<HeapRef> { self.current }
|
||||
pub fn clear_current(&mut self) { self.current = None; }
|
||||
pub fn current(&self) -> Option<HeapRef> {
|
||||
self.current
|
||||
}
|
||||
pub fn clear_current(&mut self) {
|
||||
self.current = None;
|
||||
}
|
||||
|
||||
// ---------- Sleeping operations ----------
|
||||
|
||||
@@ -63,15 +75,13 @@ impl Scheduler {
|
||||
self.next_seq = self.next_seq.wrapping_add(1);
|
||||
|
||||
// Binary search insertion point by wake_tick, then by seq to keep total order deterministic
|
||||
let idx = match self
|
||||
.sleeping
|
||||
.binary_search_by(|e| {
|
||||
if e.wake_tick == entry.wake_tick {
|
||||
e.seq.cmp(&entry.seq)
|
||||
} else {
|
||||
e.wake_tick.cmp(&entry.wake_tick)
|
||||
}
|
||||
}) {
|
||||
let idx = match self.sleeping.binary_search_by(|e| {
|
||||
if e.wake_tick == entry.wake_tick {
|
||||
e.seq.cmp(&entry.seq)
|
||||
} else {
|
||||
e.wake_tick.cmp(&entry.wake_tick)
|
||||
}
|
||||
}) {
|
||||
Ok(i) => i, // equal element position; insert after to preserve FIFO among equals
|
||||
Err(i) => i,
|
||||
};
|
||||
@@ -81,10 +91,10 @@ impl Scheduler {
|
||||
/// Move all sleeping coroutines with `wake_tick <= current_tick` to ready queue (FIFO by wake order).
|
||||
pub fn wake_ready(&mut self, current_tick: u64) {
|
||||
// Find split point where wake_tick > current_tick
|
||||
let split = self
|
||||
.sleeping
|
||||
.partition_point(|e| e.wake_tick <= current_tick);
|
||||
if split == 0 { return; }
|
||||
let split = self.sleeping.partition_point(|e| e.wake_tick <= current_tick);
|
||||
if split == 0 {
|
||||
return;
|
||||
}
|
||||
let mut ready_slice: Vec<SleepEntry> = self.sleeping.drain(0..split).collect();
|
||||
// Already in order by (wake_tick, seq); push in that order to preserve determinism
|
||||
for e in ready_slice.drain(..) {
|
||||
@@ -93,14 +103,18 @@ impl Scheduler {
|
||||
}
|
||||
|
||||
/// Returns true if there are any sleeping coroutines.
|
||||
pub fn has_sleeping(&self) -> bool { !self.sleeping.is_empty() }
|
||||
pub fn has_sleeping(&self) -> bool {
|
||||
!self.sleeping.is_empty()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
fn hr(id: u32) -> HeapRef { HeapRef(id) }
|
||||
fn hr(id: u32) -> HeapRef {
|
||||
HeapRef(id)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn fifo_ready_queue_is_deterministic() {
|
||||
|
||||
Reference in New Issue
Block a user