Skip to content

Commit

Permalink
unblock the clock lock block.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 588077026
Change-Id: I5acc410fae3e1a5b2a56ffa86e358f58d5a2f4d6
  • Loading branch information
vezhnick authored and copybara-github committed Dec 5, 2023
1 parent a38327f commit 35ad6b4
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions concordia/clocks/game_clock.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 35ad6b4

Please sign in to comment.