aboutsummaryrefslogtreecommitdiffstats
path: root/klippy/serialhdl.py
diff options
context:
space:
mode:
authorKevin O'Connor <kevin@koconnor.net>2017-09-15 13:58:05 -0400
committerKevin O'Connor <kevin@koconnor.net>2017-09-19 17:25:42 -0400
commit9d0fcca8a91e54e62733e711fbb52f2e030085e0 (patch)
tree493cf028331070b43b96423aa78893efd06c6c72 /klippy/serialhdl.py
parent857eb01bfa4389e6e475bacfe506424f2a158d15 (diff)
downloadkutter-9d0fcca8a91e54e62733e711fbb52f2e030085e0.tar.gz
kutter-9d0fcca8a91e54e62733e711fbb52f2e030085e0.tar.xz
kutter-9d0fcca8a91e54e62733e711fbb52f2e030085e0.zip
serialhdl: Reduce calculations done while holding the lock
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Diffstat (limited to 'klippy/serialhdl.py')
-rw-r--r--klippy/serialhdl.py8
1 files changed, 5 insertions, 3 deletions
diff --git a/klippy/serialhdl.py b/klippy/serialhdl.py
index 260ad708..8626cf25 100644
--- a/klippy/serialhdl.py
+++ b/klippy/serialhdl.py
@@ -53,8 +53,8 @@ class SerialReader:
params = self.msgparser.parse(response.msg[0:count])
params['#sent_time'] = response.sent_time
params['#receive_time'] = response.receive_time
+ hdl = (params['#name'], params.get('oid'))
with self.lock:
- hdl = (params['#name'], params.get('oid'))
hdl = self.handlers.get(hdl, self.handle_default)
try:
hdl(params)
@@ -160,8 +160,10 @@ class SerialReader:
# Clock tracking
def get_clock(self, eventtime):
with self.lock:
- return int(self.last_clock
- + (eventtime - self.last_clock_time) * self.min_freq)
+ last_clock = self.last_clock
+ last_clock_time = self.last_clock_time
+ min_freq = self.min_freq
+ return int(last_clock + (eventtime - last_clock_time) * min_freq)
def translate_clock(self, raw_clock):
with self.lock:
last_clock = self.last_clock