From e66365f3f41c14f7158cd18b999993abc0a62ad3 Mon Sep 17 00:00:00 2001 From: Bryan Biedenkapp Date: Mon, 15 Jul 2024 15:57:48 -0400 Subject: [PATCH] add support to sleep for shorter periods of time; --- src/common/Thread.cpp | 8 ++++++-- src/common/Thread.h | 3 ++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/common/Thread.cpp b/src/common/Thread.cpp index 4381e5ab..528fa15c 100644 --- a/src/common/Thread.cpp +++ b/src/common/Thread.cpp @@ -84,9 +84,13 @@ void Thread::detach() /* Helper to sleep the current thread. */ -void Thread::sleep(uint32_t ms) +void Thread::sleep(uint32_t ms, uint32_t us) { - ::usleep(ms * 1000); + if (us > 0U) { + ::usleep(us); + } else { + ::usleep(ms * 1000U); + } } // --------------------------------------------------------------------------- diff --git a/src/common/Thread.h b/src/common/Thread.h index 4a01937e..2e766d4c 100644 --- a/src/common/Thread.h +++ b/src/common/Thread.h @@ -77,8 +77,9 @@ public: /** * @brief Helper to sleep the current thread. * @param ms Time in milliseconds to sleep. + * @param us Time in microseconds to sleep. */ - static void sleep(uint32_t ms); + static void sleep(uint32_t ms, uint32_t us = 0U); private: pthread_t m_thread;