use lancer_core::object_layout::SchedContextObject; pub fn replenish(sc: &mut SchedContextObject, now_us: u64) { match sc.replenish_at { 0 => {} at if now_us >= at && sc.period_us > 0 => { sc.remaining_us = sc.budget_us; sc.replenish_at = at.saturating_add(sc.period_us); } _ => {} } } pub fn consume(sc: &mut SchedContextObject, elapsed_us: u64, now_us: u64) { sc.remaining_us = sc.remaining_us.saturating_sub(elapsed_us); match (sc.remaining_us, sc.replenish_at, sc.period_us) { (0, 0, period) if period > 0 => { sc.replenish_at = now_us.saturating_add(sc.period_us); } _ => {} } } pub fn mark_dispatched(sc: &mut SchedContextObject, now_us: u64) { match (sc.replenish_at, sc.period_us) { (0, period) if period > 0 => { sc.replenish_at = now_us.saturating_add(sc.period_us); } _ => {} } } pub fn is_exhausted(sc: &SchedContextObject) -> bool { sc.remaining_us == 0 }