Skip to content

Commit

Permalink
only turn allowed_blocked_microsec into a Duration once per machine, …
Browse files Browse the repository at this point in the history
…instead of up to each time checking blocking limits
  • Loading branch information
pylls committed Jul 19, 2024
1 parent ea12353 commit 3c89e3c
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions crates/maybenot/src/framework.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ struct MachineRuntime<T: crate::time::Instant> {
normal_sent: u64,
blocking_duration: T::Duration,
machine_start: T,
allowed_blocked_microsec: T::Duration,
counter_a: u64,
counter_b: u64,
}
Expand Down Expand Up @@ -115,30 +116,28 @@ where
current_time: T,
rng: R,
) -> Result<Self, Error> {
for m in machines.as_ref() {
m.validate()?;
}

if !(0.0..=1.0).contains(&max_padding_frac) {
Err(Error::PaddingLimit)?;
}
if !(0.0..=1.0).contains(&max_blocking_frac) {
Err(Error::BlockingLimit)?;
}

let runtime = vec![
MachineRuntime {
let mut runtime = Vec::with_capacity(machines.as_ref().len());
for m in machines.as_ref() {
m.validate()?;
runtime.push(MachineRuntime {
current_state: 0,
state_limit: 0,
padding_sent: 0,
normal_sent: 0,
blocking_duration: T::Duration::zero(),
machine_start: current_time,
allowed_blocked_microsec: T::Duration::from_micros(m.allowed_blocked_microsec),
counter_a: 0,
counter_b: 0,
};
machines.as_ref().len()
];
});
}

let actions = vec![None; machines.as_ref().len()];

Expand Down Expand Up @@ -510,7 +509,7 @@ where

// machine allowed blocking duration first, since it bypasses the
// other two types of limits
if m_block_dur < T::Duration::from_micros(machine.allowed_blocked_microsec) {
if m_block_dur < runtime.allowed_blocked_microsec {
// we still check against state limit, because it's machine internal
return runtime.state_limit > 0;
}
Expand Down

0 comments on commit 3c89e3c

Please sign in to comment.