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

A readers-writer lock class. More...

#include <xsens_mutex.h>

Public Member Functions

bool haveWriteClaim () const volatile
 
bool isLocked (bool write) const volatile
 
bool lock (bool write)
 Make sure that the lock has exactly the given lock state. More...
 
bool lock (LockState ls)
 Convenience function that accepts the generic LockState, forwards to lock(bool) More...
 
bool lockRead ()
 Convenience function for lock(false);. More...
 
 LockReadWrite (MutexReadWrite *mutex, LockState lockState=LS_Unlocked)
 Consturctor. More...
 
bool lockWrite ()
 Convenience function for lock(true);. More...
 
bool tryLock (bool write, uint32_t timeout=0)
 Tries to lock the write/read unlocked mutex before a given time runs out. More...
 
bool unlock () noexcept
 Unlocks the write or read locked mutex. More...
 
 ~LockReadWrite ()
 

Private Member Functions

 CHECK_LOCK_DEFINE ()
 
 LockReadWrite (LockReadWrite &&)=delete
 
 LockReadWrite (LockReadWrite const &)=delete
 
LockReadWriteoperator= (LockReadWrite &&)=delete
 
LockReadWriteoperator= (LockReadWrite const &)=delete
 

Private Attributes

volatile std::atomic_bool m_lockedR
 
volatile std::atomic_bool m_lockedW
 
MutexReadWritem_mutex
 

Detailed Description

A readers-writer lock class.

Definition at line 1090 of file xsens_mutex.h.

Constructor & Destructor Documentation

◆ LockReadWrite() [1/3]

xsens::LockReadWrite::LockReadWrite ( LockReadWrite const &  )
privatedelete

◆ LockReadWrite() [2/3]

xsens::LockReadWrite::LockReadWrite ( LockReadWrite &&  )
privatedelete

◆ LockReadWrite() [3/3]

xsens::LockReadWrite::LockReadWrite ( MutexReadWrite mutex,
LockState  lockState = LS_Unlocked 
)
inline

Consturctor.

Definition at line 1106 of file xsens_mutex.h.

◆ ~LockReadWrite()

xsens::LockReadWrite::~LockReadWrite ( )
inline

Definition at line 1119 of file xsens_mutex.h.

Member Function Documentation

◆ CHECK_LOCK_DEFINE()

xsens::LockReadWrite::CHECK_LOCK_DEFINE ( )
private

◆ haveWriteClaim()

bool xsens::LockReadWrite::haveWriteClaim ( ) const volatile
inline
Returns
True if the mutex has a write lock
Note
Do not use this function internally! The mutex may have a write claim, while the lock does not, but this function will return true.

Definition at line 1246 of file xsens_mutex.h.

◆ isLocked()

bool xsens::LockReadWrite::isLocked ( bool  write) const volatile
inline
Returns
true if the lock has at least the given state
Parameters
writeIf set to true, write mode is used, otherwise read mode

Definition at line 1238 of file xsens_mutex.h.

◆ lock() [1/2]

bool xsens::LockReadWrite::lock ( bool  write)
inline

Make sure that the lock has exactly the given lock state.

The lock will be upgraded/downgraded as required, possibly unlocking in between

Parameters
writeIf set to true, write mode is used, otherwise read mode
Returns
True if successfully locked

Definition at line 1129 of file xsens_mutex.h.

◆ lock() [2/2]

bool xsens::LockReadWrite::lock ( LockState  ls)
inline

Convenience function that accepts the generic LockState, forwards to lock(bool)

Parameters
lsIf set not to read lock state then it will lock the mutex
Returns
True if successfully locked

Definition at line 1161 of file xsens_mutex.h.

◆ lockRead()

bool xsens::LockReadWrite::lockRead ( )
inline

Convenience function for lock(false);.

Returns
True if successful

Definition at line 1169 of file xsens_mutex.h.

◆ lockWrite()

bool xsens::LockReadWrite::lockWrite ( )
inline

Convenience function for lock(true);.

Returns
True if successful

Definition at line 1177 of file xsens_mutex.h.

◆ operator=() [1/2]

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

◆ operator=() [2/2]

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

◆ tryLock()

bool xsens::LockReadWrite::tryLock ( bool  write,
uint32_t  timeout = 0 
)
inline

Tries to lock the write/read unlocked mutex before a given time runs out.

Parameters
writeIf set to true, write mode is used, otherwise read mode
timeoutThe timeout value in ms
Returns
True if the mutex is successfully locked

Definition at line 1207 of file xsens_mutex.h.

◆ unlock()

bool xsens::LockReadWrite::unlock ( )
inlinenoexcept

Unlocks the write or read locked mutex.

Returns
True if the mutex is successfully unlocked. False if it was not locked.

Definition at line 1185 of file xsens_mutex.h.

Member Data Documentation

◆ m_lockedR

volatile std::atomic_bool xsens::LockReadWrite::m_lockedR
private

Definition at line 1094 of file xsens_mutex.h.

◆ m_lockedW

volatile std::atomic_bool xsens::LockReadWrite::m_lockedW
private

Definition at line 1095 of file xsens_mutex.h.

◆ m_mutex

MutexReadWrite* xsens::LockReadWrite::m_mutex
private

Definition at line 1093 of file xsens_mutex.h.


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


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