diff --git a/concordia/clocks/game_clock.py b/concordia/clocks/game_clock.py index 65dae2e1..3b9768d9 100644 --- a/concordia/clocks/game_clock.py +++ b/concordia/clocks/game_clock.py @@ -116,6 +116,7 @@ def __init__( self._current_gear = 0 self._step_lock = threading.RLock() + self._control_lock = threading.RLock() def _gear_up(self) -> None: with self._step_lock: @@ -131,7 +132,7 @@ def _gear_down(self) -> None: @contextlib.contextmanager def higher_gear(self): - with self._step_lock: + with self._control_lock: self._gear_up() try: yield @@ -140,14 +141,14 @@ def higher_gear(self): def advance(self): """Advances time by step_size.""" - with self._step_lock: + with self._control_lock, self._step_lock: self._steps[self._current_gear] += 1 for gear in range(self._current_gear + 1, len(self._step_sizes)): self._steps[gear] = 0 self.set(self.now()) # resolve the higher gear running over the lower def set(self, time: datetime.datetime): - with self._step_lock: + with self._control_lock, self._step_lock: remainder = time - self._start for gear, step_size in enumerate(self._step_sizes): self._steps[gear] = remainder // step_size