Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
OSMutexLock Class Reference

Class to allow convenient locking and unlocking of mutexes in a C context. More...

#include <OS.hxx>

Public Member Functions

 OSMutexLock (OSMutex *mutex)
 Constructor.
 
 OSMutexLock (os_mutex_t *mutex)
 Constructor.
 

Private Member Functions

 DISALLOW_COPY_AND_ASSIGN (OSMutexLock)
 

Private Attributes

os_mutex_t * mutex_
 Mutex we are having locked.
 

Detailed Description

Class to allow convenient locking and unlocking of mutexes in a C context.

The mutex will be automatically unlocked when the context is left, even if there are multiple return, break or continue statements.

Usage:

void foo() { // ...non-critical-section code here... { OSMutexLock locker(&mutex_); // ...critical section here... if (error) return; // ...more critical code here... } // ...at this point the mutex is unlocked... // ...more non-critical-section code here... }

Definition at line 493 of file OS.hxx.

Constructor & Destructor Documentation

◆ OSMutexLock() [1/2]

OSMutexLock::OSMutexLock ( OSMutex mutex)
inline

Constructor.

Parameters
mutexis the mutex to lock.

Definition at line 497 of file OS.hxx.

◆ OSMutexLock() [2/2]

OSMutexLock::OSMutexLock ( os_mutex_t *  mutex)
inline

Constructor.

Parameters
mutexis the mutex to lock.

Definition at line 504 of file OS.hxx.

◆ ~OSMutexLock()

OSMutexLock::~OSMutexLock ( )
inline

Definition at line 510 of file OS.hxx.

Member Data Documentation

◆ mutex_

os_mutex_t* OSMutexLock::mutex_
private

Mutex we are having locked.

Definition at line 518 of file OS.hxx.


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