Public Member Functions | Private Member Functions | Private Attributes | List of all members
xsens::WaitCondition Class Reference

A platform independent wait condition implementation. More...

#include <xsens_mutex.h>

Public Member Functions

void broadcast ()
 Unblock all waiting threads. More...
 
void signal ()
 Unblock a single waiting thread. More...
 
bool wait ()
 Wait until we're signalled to continue. More...
 
bool wait (uint32_t timeout)
 Wait until we're signalled to continue, or until timeout [ms] has passed. More...
 
 WaitCondition (Mutex &m)
 Create a wait condition. More...
 
 ~WaitCondition ()
 Destroy the wait condition. More...
 

Private Member Functions

WaitConditionoperator= (WaitCondition &&)=delete
 
WaitConditionoperator= (WaitCondition const &)=delete
 
 WaitCondition (WaitCondition &&)=delete
 
 WaitCondition (WaitCondition const &)=delete
 

Private Attributes

clockid_t m_clockId
 
pthread_cond_t m_cond
 
pthread_condattr_t m_condattr
 
Mutexm_mutex
 

Detailed Description

A platform independent wait condition implementation.

Wait conditions are used to halt consumer threads until changes are made to data they operate on.

Creating the wait condition:

Mutex mut;
WaitCondition wc(&mut);

Consumer thread:

void func()
{
Lock locker(&mut);
if (!wc.wait()) // unlocks the mutex and waits for a signal
// the mutex is claimed
return;
// mutex is claimed
// copy data
lock.unlock();
// work with data
}

Feeder thread:

void func()
{
Lock locker(&mut);
// update data
wc.signal(); // signal that changes have been made
// alternatively, use wc.broadcast() to allow multiple consumers to handle the data
}

Definition at line 1806 of file xsens_mutex.h.

Constructor & Destructor Documentation

◆ WaitCondition() [1/3]

xsens::WaitCondition::WaitCondition ( WaitCondition const &  )
privatedelete

◆ WaitCondition() [2/3]

xsens::WaitCondition::WaitCondition ( WaitCondition &&  )
privatedelete

◆ WaitCondition() [3/3]

xsens::WaitCondition::WaitCondition ( Mutex m)
explicit

Create a wait condition.

Definition at line 929 of file threading.cpp.

◆ ~WaitCondition()

xsens::WaitCondition::~WaitCondition ( )

Destroy the wait condition.

Definition at line 951 of file threading.cpp.

Member Function Documentation

◆ broadcast()

void xsens::WaitCondition::broadcast ( )

Unblock all waiting threads.

Definition at line 977 of file threading.cpp.

◆ operator=() [1/2]

WaitCondition& xsens::WaitCondition::operator= ( WaitCondition &&  )
privatedelete

◆ operator=() [2/2]

WaitCondition& xsens::WaitCondition::operator= ( WaitCondition const &  )
privatedelete

◆ signal()

void xsens::WaitCondition::signal ( )

Unblock a single waiting thread.

Definition at line 967 of file threading.cpp.

◆ wait() [1/2]

bool xsens::WaitCondition::wait ( )

Wait until we're signalled to continue.

 \details Before calling this function, it is required that the mutex
 provided during construction is _locked_. This function unlocks the mutex
 internally, and returns with the mutex locked again.

 \return true if we were signalled, false otherwise

Definition at line 994 of file threading.cpp.

◆ wait() [2/2]

bool xsens::WaitCondition::wait ( uint32_t  timeout)

Wait until we're signalled to continue, or until timeout [ms] has passed.

 \details Before calling this function, it is required that the mutex
 provided during construction is _locked_. This function unlocks the mutex
 internally, and returns with the mutex locked again.

 \param timeout The timeout value in ms

 \return true if we were signalled, false otherwise

Definition at line 1013 of file threading.cpp.

Member Data Documentation

◆ m_clockId

clockid_t xsens::WaitCondition::m_clockId
private

Definition at line 1830 of file xsens_mutex.h.

◆ m_cond

pthread_cond_t xsens::WaitCondition::m_cond
private

Definition at line 1825 of file xsens_mutex.h.

◆ m_condattr

pthread_condattr_t xsens::WaitCondition::m_condattr
private

Definition at line 1826 of file xsens_mutex.h.

◆ m_mutex

Mutex& xsens::WaitCondition::m_mutex
private

Definition at line 1833 of file xsens_mutex.h.


The documentation for this class was generated from the following files:
xsens::WaitCondition::WaitCondition
WaitCondition(WaitCondition const &)=delete


xsens_mti_driver
Author(s):
autogenerated on Sun Sep 3 2023 02:43:23