diff --git a/nexosim/src/simulation.rs b/nexosim/src/simulation.rs index 1a606a5..cf20b02 100644 --- a/nexosim/src/simulation.rs +++ b/nexosim/src/simulation.rs @@ -344,17 +344,15 @@ impl Simulation { /// Runs the executor. fn run(&mut self) -> Result<(), ExecutionError> { - // Defensive programming, shouldn't happen - if !self.is_terminated && self.is_halted.load(Ordering::Relaxed) { - self.is_terminated = true; - return Err(ExecutionError::Halted); - } - - // Defensive programming, shouldn't happen if self.is_terminated { return Err(ExecutionError::Terminated); } + if self.is_halted.load(Ordering::Relaxed) { + self.is_terminated = true; + return Err(ExecutionError::Halted); + } + self.executor.run(self.timeout).map_err(|e| { self.is_terminated = true; @@ -409,15 +407,15 @@ impl Simulation { &mut self, upper_time_bound: Option, ) -> Result, ExecutionError> { - if !self.is_terminated && self.is_halted.load(Ordering::Relaxed) { - self.is_terminated = true; - return Err(ExecutionError::Halted); - } - if self.is_terminated { return Err(ExecutionError::Terminated); } + if self.is_halted.load(Ordering::Relaxed) { + self.is_terminated = true; + return Err(ExecutionError::Halted); + } + // Function pulling the next action. If the action is periodic, it is // immediately re-scheduled. fn pull_next_action(scheduler_queue: &mut MutexGuard) -> Action {