Fixposition SDK 0.0.0-heads/main-0-g7b59b93
Collection of c++ libraries and apps for use with Fixposition products
|
A binary semaphore, useful for thread synchronisation. More...
#include <thread.hpp>
Public Member Functions | |
void | Notify () |
Notify ("signal", "give") | |
bool | WaitFor (const uint32_t millis) |
Wait (take), with timeout. | |
bool | WaitUntil (const uint32_t period, const uint32_t min_sleep=0) |
Wait (take), with timout aligned to a period. | |
A binary semaphore, useful for thread synchronisation.
The default state is "taken", that is, WaitFor() and WaitUntil() block (sleep) until the semaphore is "given" using Notify(). See the example in the Thread class documentation below.
Definition at line 49 of file thread.hpp.
bool fpsdk::common::thread::BinarySemaphore::WaitFor | ( | const uint32_t | millis | ) |
Wait (take), with timeout.
[in] | millis | Number of [ms] to sleep, must be > 0 |
bool fpsdk::common::thread::BinarySemaphore::WaitUntil | ( | const uint32_t | period, |
const uint32_t | min_sleep = 0 ) |
Wait (take), with timout aligned to a period.
This blocks (sleeps) until the start of the next millis period is reached (or the semaphore has been taken). The period is aligned to the system clock. For example, with a period of 500ms it would timeout at t+0.0s, t+0.5s, t+1.0s, t+1.5s, etc. If the calculated wait duration is less then the given minimal wait duration, it waits longer than one period in order to achieve the minimal wait duration and still timeout on the start of a period.
Note that this works on the actual system clock. In ROS replay scenario this may not behave as expected as the fake ROS system clock may be faster or slower than the actual system clock.
[in] | period | Period duration [ms], must be > 0 |
[in] | min_sleep | Minimal sleep duration [ms], must be < period |