Kea  1.5.0
isc::util::thread::Mutex::Locker Class Reference

This holds a lock on a Mutex. More...

#include <sync.h>

+ Inheritance diagram for isc::util::thread::Mutex::Locker:

Classes

struct  AlreadyLocked
 Exception thrown when the mutex is already locked and a non-blocking locker is attempted around it. More...
 

Public Member Functions

 Locker (Mutex &mutex, bool block=true)
 Constructor. More...
 
 ~Locker ()
 Destructor. More...
 

Detailed Description

This holds a lock on a Mutex.

To lock a mutex, create a locker. It'll get unlocked when the locker is destroyed.

If you create the locker on the stack or using some other "garbage collecting" mechanism (unique_ptr, for example), it ensures exception safety with regards to the mutex - it'll get released on the exit of function no matter by what means.

Definition at line 72 of file sync.h.

Constructor & Destructor Documentation

◆ Locker()

isc::util::thread::Mutex::Locker::Locker ( Mutex mutex,
bool  block = true 
)
inline

Constructor.

Locks the mutex. May block for extended period of time if block is true.

Exceptions
isc::InvalidOperationwhen OS reports error. This usually means an attempt to use the mutex in a wrong way (locking a mutex second time from the same thread, for example).
AlreadyLockedif block is false and the mutex is already locked.

Definition at line 92 of file sync.h.

References isc_throw.

◆ ~Locker()

isc::util::thread::Mutex::Locker::~Locker ( )
inline

Destructor.

Unlocks the mutex.

Definition at line 107 of file sync.h.


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