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

A Mutex to synchronize access to resources between threads. More...

#include <mutex.hpp>

Collaboration diagram for dodo::threads::Mutex:

Public Member Functions

 Mutex ()
 Construct a Mutex. More...
 
virtual ~Mutex ()
 Destruct a Mutex. More...
 
void lock ()
 Waits for a Mutex and locks it (atomically). More...
 
bool tryLock ()
 If the Mutex is currently not locked, lock it and return true. More...
 
void unLock ()
 Unlocks the Mutex. More...
 

Private Attributes

std::mutex mutex_
 the internal std::mutex More...
 

Detailed Description

A Mutex to synchronize access to resources between threads.

Use a Mutexer to control a Mutex by mere scope.

See also
Mutexer
std::mutex

Definition at line 39 of file mutex.hpp.

Constructor & Destructor Documentation

◆ Mutex()

dodo::threads::Mutex::Mutex ( )
inline

Construct a Mutex.

Definition at line 45 of file mutex.hpp.

◆ ~Mutex()

virtual dodo::threads::Mutex::~Mutex ( )
inlinevirtual

Destruct a Mutex.

Definition at line 50 of file mutex.hpp.

Member Function Documentation

◆ lock()

void dodo::threads::Mutex::lock ( )
inline

Waits for a Mutex and locks it (atomically).

You must not call lock if the lock is already held by the calling thread, that is a deadlock.

See also
std::mutex::lock()

Definition at line 57 of file mutex.hpp.

References mutex_.

Referenced by dodo::threads::Mutexer::Mutexer().

Here is the caller graph for this function:

◆ tryLock()

bool dodo::threads::Mutex::tryLock ( )
inline

If the Mutex is currently not locked, lock it and return true.

If the Mutex is locked, return false. You must not call lock if the lock is alread held by the calling thread, that is a deadlock. Mutex from the same thread twice - that is a deadlock.

Returns
true if the Mutex was locked. false if the Mutex was already locked.
See also
std::mutex::try_lock()

Definition at line 66 of file mutex.hpp.

References mutex_.

◆ unLock()

void dodo::threads::Mutex::unLock ( )
inline

Unlocks the Mutex.

Calling unLOck whilst the calling thread is not holding the lock causes undefined behavior in the Mutex.

See also
std::mutex::unlock()

Definition at line 73 of file mutex.hpp.

References mutex_.

Referenced by dodo::threads::Mutexer::~Mutexer().

Here is the caller graph for this function:

Field Documentation

◆ mutex_

std::mutex dodo::threads::Mutex::mutex_
private

the internal std::mutex

Definition at line 73 of file mutex.hpp.

Referenced by lock(), tryLock(), and unLock().


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