From cb82b1dafca51f92aa69e70205fd643e51a615d8 Mon Sep 17 00:00:00 2001 From: Emmanuel Durand Date: Fri, 13 May 2022 14:00:12 -0400 Subject: [PATCH] Fixed Python interpreted not respecting the update rate --- src/controller/controller_pythonembedded.cpp | 2 +- src/utils/timer.h | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/controller/controller_pythonembedded.cpp b/src/controller/controller_pythonembedded.cpp index d6ae1316..78410f05 100644 --- a/src/controller/controller_pythonembedded.cpp +++ b/src/controller/controller_pythonembedded.cpp @@ -1281,7 +1281,7 @@ void PythonEmbedded::loop() lockAttributes.unlock(); pythonMutexLock.unlock(); - Timer::get() >> 1.f / static_cast(_updateRate) * 1000.f >> timerName; + Timer::get() >> 1000000ull / _updateRate >> timerName; } pythonMutexLock.lock(); diff --git a/src/utils/timer.h b/src/utils/timer.h index a9f487ce..9f255590 100644 --- a/src/utils/timer.h +++ b/src/utils/timer.h @@ -26,6 +26,7 @@ #define SPLASH_TIMER_H #include +#include #include #include @@ -115,7 +116,7 @@ class Timer */ bool waitUntilDuration(const std::string& name, unsigned long long duration) { - std::lock_guard lock(_timerMutex); + std::unique_lock lock(_timerMutex); if (!_enabled) return false; @@ -144,6 +145,7 @@ class Timer _durationMap[name] = std::max(duration, elapsed); else durationIt->second = std::max(duration, elapsed); + lock.unlock(); nanosleep(&nap, NULL);