Public Member Functions | Protected Types | Static Protected Member Functions | Protected Attributes | Static Protected Attributes | List of all members
RTT::os::SharedMutex Class Reference

An object oriented wrapper around a shared mutex (multiple readers allowed, but only one writer with exclusive access). More...

#include <Mutex.hpp>

Inheritance diagram for RTT::os::SharedMutex:
Inheritance graph
[legend]

Public Member Functions

virtual void lock ()
 
void lock_shared ()
 
 SharedMutex ()
 
virtual bool timedlock (Seconds s)
 
virtual bool timedlock_shared (Seconds s)
 
virtual bool trylock ()
 
virtual bool trylock_shared ()
 
virtual void unlock ()
 
virtual void unlock_shared ()
 
virtual ~SharedMutex ()
 
- Public Member Functions inherited from RTT::os::MutexInterface
virtual ~MutexInterface ()
 

Protected Types

typedef unsigned int Status
 

Static Protected Member Functions

static unsigned int readers (Status status)
 
static unsigned int waitToRead (Status status)
 
static unsigned int writers (Status status)
 

Protected Attributes

Semaphore read_semaphore
 
oro_atomic_t status
 
Semaphore write_semaphore
 

Static Protected Attributes

static const Status one_reader = (1 << 0)
 
static const Status one_wait_to_read = (1 << 10)
 
static const Status one_writer = (1 << 20)
 
static const Status status_mask = (1 << 10) - 1
 

Detailed Description

An object oriented wrapper around a shared mutex (multiple readers allowed, but only one writer with exclusive access).

A mutex can only be unlock()'ed, by the thread which lock()'ed it. A trylock is a non blocking lock action which fails or succeeds.

Implementation is motivated by http://preshing.com/20150316/semaphores-are-surprisingly-versatile/#a-lightweight-semaphore-with-partial-spinning.

See also
MutexLock, MutexTryLock, SharedMutexLock, SharedMutexTryLock, Mutex

Definition at line 346 of file Mutex.hpp.

Member Typedef Documentation

typedef unsigned int RTT::os::SharedMutex::Status
protected

Definition at line 349 of file Mutex.hpp.

Constructor & Destructor Documentation

RTT::os::SharedMutex::SharedMutex ( )
inline

Initialize a shared Mutex.

Definition at line 373 of file Mutex.hpp.

virtual RTT::os::SharedMutex::~SharedMutex ( )
inlinevirtual

Destroy a shared Mutex.

Definition at line 383 of file Mutex.hpp.

Member Function Documentation

virtual void RTT::os::SharedMutex::lock ( )
inlinevirtual

Implements RTT::os::MutexInterface.

Definition at line 388 of file Mutex.hpp.

void RTT::os::SharedMutex::lock_shared ( )
inlinevirtual

Obtain shared ownership of this mutex.

Reimplemented from RTT::os::MutexInterface.

Definition at line 457 of file Mutex.hpp.

static unsigned int RTT::os::SharedMutex::readers ( Status  status)
inlinestaticprotected

Definition at line 359 of file Mutex.hpp.

virtual bool RTT::os::SharedMutex::timedlock ( Seconds  s)
inlinevirtual

Lock this mutex exclusively, but don't wait longer for the lock than the specified timeout.

Parameters
sThe maximum time to wait before aqcuiring the lock.
Note
not implemented for this type of mutex
Returns
false

Implements RTT::os::MutexInterface.

Definition at line 448 of file Mutex.hpp.

virtual bool RTT::os::SharedMutex::timedlock_shared ( Seconds  s)
inlinevirtual

Attempt to obtain shared ownership of this mutex, but don't wait longer for the lock than the specified timeout.

Parameters
sThe maximum time to wait before aqcuiring the lock.
Note
not implemented for this type of mutex
Returns
false

Reimplemented from RTT::os::MutexInterface.

Definition at line 515 of file Mutex.hpp.

virtual bool RTT::os::SharedMutex::trylock ( )
inlinevirtual

Try to lock this mutex exclusively

Note
not implemented for this type of mutex
Returns
false

Implements RTT::os::MutexInterface.

Definition at line 434 of file Mutex.hpp.

virtual bool RTT::os::SharedMutex::trylock_shared ( )
inlinevirtual

Attempt to obtain shared ownership of this mutex

Note
not implemented for this type of mutex
Returns
false

Reimplemented from RTT::os::MutexInterface.

Definition at line 501 of file Mutex.hpp.

virtual void RTT::os::SharedMutex::unlock ( )
inlinevirtual

Implements RTT::os::MutexInterface.

Definition at line 402 of file Mutex.hpp.

virtual void RTT::os::SharedMutex::unlock_shared ( )
inlinevirtual

Release shared ownership of this mutex.

Reimplemented from RTT::os::MutexInterface.

Definition at line 480 of file Mutex.hpp.

static unsigned int RTT::os::SharedMutex::waitToRead ( Status  status)
inlinestaticprotected

Definition at line 362 of file Mutex.hpp.

static unsigned int RTT::os::SharedMutex::writers ( Status  status)
inlinestaticprotected

Definition at line 365 of file Mutex.hpp.

Member Data Documentation

const Status RTT::os::SharedMutex::one_reader = (1 << 0)
staticprotected

Definition at line 354 of file Mutex.hpp.

const Status RTT::os::SharedMutex::one_wait_to_read = (1 << 10)
staticprotected

Definition at line 355 of file Mutex.hpp.

const Status RTT::os::SharedMutex::one_writer = (1 << 20)
staticprotected

Definition at line 356 of file Mutex.hpp.

Semaphore RTT::os::SharedMutex::read_semaphore
protected

Definition at line 351 of file Mutex.hpp.

oro_atomic_t RTT::os::SharedMutex::status
protected

Definition at line 350 of file Mutex.hpp.

const Status RTT::os::SharedMutex::status_mask = (1 << 10) - 1
staticprotected

Definition at line 357 of file Mutex.hpp.

Semaphore RTT::os::SharedMutex::write_semaphore
protected

Definition at line 352 of file Mutex.hpp.


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


rtt
Author(s): RTT Developers
autogenerated on Tue Jun 25 2019 19:33:46