Lely core libraries  2.2.5
lely::util::UnlockGuard< Mutex > Class Template Reference

A mutex wrapper that provides a convenient RAII-style mechanism for releasing a mutex for the duration of a scoped block. More...

#include <mutex.hpp>

Public Types

typedef Mutex MutexType
 The type of the mutex to unlock. More...
 

Public Member Functions

 UnlockGuard (MutexType &m)
 Releases ownership of m and calls m.unlock(). More...
 
 UnlockGuard (MutexType &m, ::std::adopt_lock_t)
 Releases ownership of m without attempting to unlock it. More...
 
 ~UnlockGuard ()
 Acquires ownership of m and calls m.lock(), where m is the mutex passed to the constructor.
 

Detailed Description

template<class Mutex>
class lely::util::UnlockGuard< Mutex >

A mutex wrapper that provides a convenient RAII-style mechanism for releasing a mutex for the duration of a scoped block.

When an UnlockGuard object is created, it attempts to release ownership of the mutex it is given. When control leaves the scope in which the UnlockGuard object was created, the UnlockGuard is destructed and the mutex reacquired.

Definition at line 57 of file mutex.hpp.

Member Typedef Documentation

◆ MutexType

template<class Mutex>
typedef Mutex lely::util::UnlockGuard< Mutex >::MutexType

The type of the mutex to unlock.

The type must meet the BasicLockable requirements.

Definition at line 63 of file mutex.hpp.

Constructor & Destructor Documentation

◆ UnlockGuard() [1/2]

template<class Mutex>
lely::util::UnlockGuard< Mutex >::UnlockGuard ( MutexType m)
inlineexplicit

Releases ownership of m and calls m.unlock().

The behavior is undefined if the current thread does not own m.

Definition at line 69 of file mutex.hpp.

◆ UnlockGuard() [2/2]

template<class Mutex>
lely::util::UnlockGuard< Mutex >::UnlockGuard ( MutexType m,
::std::adopt_lock_t   
)
inline

Releases ownership of m without attempting to unlock it.

The behavior is undefined if the current thread already owns m.

Definition at line 75 of file mutex.hpp.


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