![]() |
Kea
1.5.0
|
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 |
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.
| 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.
| std::bad_alloc | In case allocation of something (memory, the OS mutex) fails. |
| isc::InvalidOperation | Other unspecified errors around the mutex. This should be rare. |
Definition at line 57 of file sync.cc.
References isc::ha::impl, and isc_throw.
| 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:| bool isc::util::thread::Mutex::locked | ( | ) | const |