dodo  0.0.1
A C++ library to create containerized Linux services
dodo::threads::Mutexer Class Reference

Waits for and locks the Mutex on construction, unlocks the Mutex when this Mutexer is destructed. More...

#include <mutex.hpp>

Collaboration diagram for dodo::threads::Mutexer:

Public Member Functions

 Mutexer (Mutex &mutex)
 Constructor. More...
 
 ~Mutexer ()
 Destructor. More...
 

Private Attributes

Mutexmutex_
 Reference to the guarded mutex. More...
 

Detailed Description

Waits for and locks the Mutex on construction, unlocks the Mutex when this Mutexer is destructed.

In the below code, it would be safe to call addInt from multiple threads. The Mutexer object calls thelist_mutex.lock() when constructed, and thelist_mutex.unLock() when it goes out of scope( the function returns or an exception is thrown).

// Mutex to protect thelist
threads::Mutex thelist_mutex;
std::list<int> thelist;
function addInt( int i ) {
Mutexer lock( thelist_mutex );
thelist.push_back( i );
}
See also
Mutex

Definition at line 100 of file mutex.hpp.

Constructor & Destructor Documentation

◆ Mutexer()

dodo::threads::Mutexer::Mutexer ( Mutex mutex)
inline

Constructor.

Parameters
mutexThe mutex to guard.

Definition at line 106 of file mutex.hpp.

References dodo::threads::Mutex::lock(), and mutex_.

Here is the call graph for this function:

◆ ~Mutexer()

dodo::threads::Mutexer::~Mutexer ( )
inline

Destructor.

Unlocks the guarded mutex.

Definition at line 112 of file mutex.hpp.

References mutex_, and dodo::threads::Mutex::unLock().

Here is the call graph for this function:

Field Documentation

◆ mutex_

Mutex& dodo::threads::Mutexer::mutex_
private

Reference to the guarded mutex.

Definition at line 112 of file mutex.hpp.

Referenced by Mutexer(), and ~Mutexer().


The documentation for this class was generated from the following file:
dodo::threads::Mutexer::Mutexer
Mutexer(Mutex &mutex)
Constructor.
Definition: mutex.hpp:106