Skip to content

Commit 4ef13ef

Browse files
committed
fix losing cached controllers when kernel wakes up during sleep
1 parent 13e3b8a commit 4ef13ef

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

src/hhd/controller/lib/ccache.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,10 @@ def __init__(self, cache_timeout=CACHE_TIMEOUT) -> None:
1717

1818
def _close_cached(self):
1919
with self._cond:
20-
start = time.perf_counter()
21-
curr = time.perf_counter()
22-
while curr - start < self.cache_timeout and not self._should_exit.is_set():
20+
delay = 0
21+
while delay < self.cache_timeout and not self._should_exit.is_set():
2322
self._cond.wait(UPDATE_T)
24-
next = time.perf_counter()
23+
delay += UPDATE_T
2524
if self._cached:
2625
# Send fake events to keep everyone happy
2726
# Both steam and kernel
@@ -32,10 +31,10 @@ def _close_cached(self):
3231
# Use .95 to prevent racing ahead of the IMU ts
3332
if hasattr(self._cached, "last_imu_ts"):
3433
ctime = getattr(self._cached, "last_imu_ts") + int(
35-
(next - curr) * 0.95 * 1e9
34+
delay * 0.95 * 1e9
3635
)
3736
else:
38-
ctime = int(next * 1e9)
37+
ctime = int(delay * 1e9)
3938

4039
# Send a lot of noise to the accel value to avoid
4140
# steam recalibrating. Only RPCS3 and dolphin might
@@ -54,7 +53,6 @@ def _close_cached(self):
5453
else:
5554
# Exit if cached became null during sleep
5655
break
57-
curr = next
5856
if self._cached:
5957
self._cached.close(True, in_cache=True)
6058
self._cached = None

0 commit comments

Comments
 (0)