EPICS ARCHIVER V4
|
A mutex with informational name and lock order. More...
#include <OrderedMutex.h>
Public Member Functions | |
OrderedMutex (const char *name, size_t order) | |
Create mutex with name and lock order. More... | |
~OrderedMutex () | |
Destructor. More... | |
const stdString & | getName () const |
size_t | getOrder () const |
void | lock (const char *file, size_t line) |
Lock the mutex. More... | |
void | unlock () |
Unlock the mutex. More... | |
Static Public Attributes | |
static const size_t | Throttle = 101 |
Lock order used by Tools::Throttle. More... | |
static const size_t | ConcurrentList = 100 |
Lock order used by Tools::ConcurrentList. More... | |
A mutex with informational name and lock order.
Meant to help with deadlock-detection based on a predetermined lock order. For example, if an application defines locks with order
OrderedMutex a("a", 1);
OrderedMutex b("b", 2);
OrderedMutex c("c", 3);
, then one has to take them individually or in the order a, b, c
.
Attempts to take these mutexes out of order, which could result in deadlocks, are detected. For example, locking b, a
or c, a
will result in a printout of all threads and the locks which they currently hold, followed by an exception.
OrderedMutex::OrderedMutex | ( | const char * | name, |
size_t | order | ||
) |
Create mutex with name and lock order.
OrderedMutex::~OrderedMutex | ( | ) |
Destructor.
|
inline |
|
inline |
void OrderedMutex::lock | ( | const char * | file, |
size_t | line | ||
) |
Lock the mutex.
Attempts to lock this mutex while higher-order mutexes are already taken will result in an exception.
Parameters file and line will be used in error messages.
void OrderedMutex::unlock | ( | ) |
Unlock the mutex.
|
static |
Lock order used by Tools::ConcurrentList.
|
static |
Lock order used by Tools::Throttle.