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

Mutex with very simple interface. More...

#include <sync.h>

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

Classes

class  Impl
 
class  Locker
 This holds a lock on a Mutex. More...
 

Public Member Functions

 Mutex ()
 Constructor. More...
 
 ~Mutex ()
 Destructor. More...
 
bool locked () const
 If the mutex is currently locked. More...
 

Friends

class CondVar
 

Detailed Description

Mutex with very simple interface.

Since mutexes are very system dependent, we create our own wrapper around whatever is available on the system and hide it.

To use this mutex, create it and then lock and unlock it by creating the Mutex::Locker object.

Also, as mutex is a low-level system object, an error might happen at any operation with it. We convert many errors to the isc::InvalidOperation, since the errors usually happen only when used in a wrong way. Any methods or constructors in this class can throw. Allocation errors are converted to std::bad_alloc (for example when OS-dependent limit of mutexes is exceeded). Some errors which usually mean a programmer error abort the program, since there could be no safe way to recover from them.

The current interface is somewhat minimalist. If we ever need more, we can add it later.

Definition at line 39 of file sync.h.

Constructor & Destructor Documentation

◆ Mutex()

isc::util::thread::Mutex::Mutex ( )

Constructor.

Creates a mutex. It is a non-recursive mutex (can be locked just once, if the same threads tries to lock it again, Bad Things Happen).

Depending on compilation parameters and OS, the mutex may or may not do some error and sanity checking. However, such checking is meant only to aid development, not rely on it as a feature.

Exceptions
std::bad_allocIn case allocation of something (memory, the OS mutex) fails.
isc::InvalidOperationOther unspecified errors around the mutex. This should be rare.

Definition at line 57 of file sync.cc.

References isc::ha::impl, and isc_throw.

◆ ~Mutex()

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

Destructor.

Destroys the mutex. It is not allowed to destroy a mutex which is currently locked. This means a Locker created with this Mutex must never live longer than the Mutex itself.

Definition at line 99 of file sync.cc.

References locked(), and isc::util::thread::Mutex::Impl::mutex.

+ Here is the call graph for this function:

Member Function Documentation

◆ locked()

bool isc::util::thread::Mutex::locked ( ) const

If the mutex is currently locked.

This is debug aiding method only. And it might be unavailable in non-debug build (because keeping the state might be needlessly slow).

Todo:
Disable in non-debug build

Referenced by ~Mutex().

Friends And Related Function Documentation

◆ CondVar

friend class CondVar
friend

Definition at line 140 of file sync.h.


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