Fixposition SDK 0.0.0-heads/main-0-g7b59b93
Collection of c++ libraries and apps for use with Fixposition products
Loading...
Searching...
No Matches
fpsdk::common::thread::BinarySemaphore Class Reference

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.
 

Detailed Description

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.

Member Function Documentation

◆ WaitFor()

bool fpsdk::common::thread::BinarySemaphore::WaitFor ( const uint32_t millis)

Wait (take), with timeout.

Parameters
[in]millisNumber of [ms] to sleep, must be > 0
Returns
true if taken (within time limit), false if the timeout has expired

◆ WaitUntil()

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.

Parameters
[in]periodPeriod duration [ms], must be > 0
[in]min_sleepMinimal sleep duration [ms], must be < period
Returns
true if taken (within time limit), false if the timeout has expired or period was 0

The documentation for this class was generated from the following file: