Nothing to see here, move along
at main 35 lines 1.0 kB view raw
1use lancer_core::object_layout::SchedContextObject; 2 3pub fn replenish(sc: &mut SchedContextObject, now_us: u64) { 4 match sc.replenish_at { 5 0 => {} 6 at if now_us >= at && sc.period_us > 0 => { 7 sc.remaining_us = sc.budget_us; 8 sc.replenish_at = at.saturating_add(sc.period_us); 9 } 10 _ => {} 11 } 12} 13 14pub fn consume(sc: &mut SchedContextObject, elapsed_us: u64, now_us: u64) { 15 sc.remaining_us = sc.remaining_us.saturating_sub(elapsed_us); 16 match (sc.remaining_us, sc.replenish_at, sc.period_us) { 17 (0, 0, period) if period > 0 => { 18 sc.replenish_at = now_us.saturating_add(sc.period_us); 19 } 20 _ => {} 21 } 22} 23 24pub fn mark_dispatched(sc: &mut SchedContextObject, now_us: u64) { 25 match (sc.replenish_at, sc.period_us) { 26 (0, period) if period > 0 => { 27 sc.replenish_at = now_us.saturating_add(sc.period_us); 28 } 29 _ => {} 30 } 31} 32 33pub fn is_exhausted(sc: &SchedContextObject) -> bool { 34 sc.remaining_us == 0 35}