Skip to content

Commit

Permalink
add support to sleep for shorter periods of time;
Browse files Browse the repository at this point in the history
  • Loading branch information
gatekeep committed Jul 15, 2024
1 parent 7ec138e commit e66365f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
8 changes: 6 additions & 2 deletions src/common/Thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

// ---------------------------------------------------------------------------
Expand Down
3 changes: 2 additions & 1 deletion src/common/Thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,9 @@ class HOST_SW_API Thread {
/**
* @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;
Expand Down

0 comments on commit e66365f

Please sign in to comment.