#include <RobustMutex.hpp>
Definition at line 20 of file RobustMutex.hpp.
◆ RobustMutex() [1/2]
uhallibs::ipc::RobustMutex::RobustMutex |
( |
| ) |
|
Definition at line 10 of file RobustMutex.cpp.
11 pthread_mutexattr_t lAttr;
12
13 int s = pthread_mutexattr_init(&lAttr);
14 if (s != 0) {
15 exception::MutexError lExc;
16 log(lExc,
"Error code ", uhal::Integer(s),
" (",
strerror(s),
17 ") returned in mutex attr initialisation");
18 throw lExc;
19 }
20
21 s = pthread_mutexattr_setpshared(&lAttr, PTHREAD_PROCESS_SHARED);
22 if (s != 0) {
23 exception::MutexError lExc;
24 log(lExc,
"Error code ", uhal::Integer(s),
" (",
strerror(s),
25 ") returned by pthread_mutexattr_setpshared");
26 throw lExc;
27 }
28
29 s = pthread_mutexattr_setrobust(&lAttr, PTHREAD_MUTEX_ROBUST);
30 if (s != 0) {
31 exception::MutexError lExc;
32 log(lExc,
"Error code ", uhal::Integer(s),
" (",
strerror(s),
33 ") returned by pthread_mutexattr_setrobust");
34 throw lExc;
35 }
36
37 s = pthread_mutex_init(&
mMutex, &lAttr);
38 if (s != 0) {
39 exception::MutexError lExc;
40 log(lExc,
"Error code ", uhal::Integer(s),
" (",
strerror(s),
41 ") returned in mutex initialisation");
42 throw lExc;
43 }
44}
const std::string strerror(int error)
Convert C error number to string.
◆ ~RobustMutex()
uhallibs::ipc::RobustMutex::~RobustMutex |
( |
| ) |
|
◆ RobustMutex() [2/2]
uhallibs::ipc::RobustMutex::RobustMutex |
( |
const RobustMutex & | | ) |
|
|
private |
◆ endSession()
void uhallibs::ipc::RobustMutex::endSession |
( |
| ) |
|
◆ getCounter()
uint64_t uhallibs::ipc::RobustMutex::getCounter |
( |
| ) |
const |
◆ isActive()
bool uhallibs::ipc::RobustMutex::isActive |
( |
| ) |
const |
◆ lock()
void uhallibs::ipc::RobustMutex::lock |
( |
| ) |
|
Definition at line 48 of file RobustMutex.cpp.
48 {
49 int s = pthread_mutex_lock(&
mMutex);
50 bool lLastOwnerDied = (
s == EOWNERDEAD);
51 if (lLastOwnerDied)
s = pthread_mutex_consistent(&
mMutex);
52
53 if (s != 0) {
54 exception::MutexError lExc;
55 log(lExc,
"Error code ", uhal::Integer(s),
" (",
strerror(s),
") returned when ",
56 lLastOwnerDied ? "making mutex state consistent" : "locking mutex");
57 throw lExc;
58 }
59}
◆ startSession()
void uhallibs::ipc::RobustMutex::startSession |
( |
| ) |
|
◆ unlock()
void uhallibs::ipc::RobustMutex::unlock |
( |
| ) |
|
Definition at line 61 of file RobustMutex.cpp.
61 {
62 int s = pthread_mutex_unlock(&
mMutex);
63 if (s != 0)
64 log(uhal::Error(),
"Error code ", uhal::Integer(s),
" (",
strerror(s),
65 ") returned when unlocking mutex");
66}
◆ mCount
uint64_t uhallibs::ipc::RobustMutex::mCount |
|
private |
◆ mMutex
pthread_mutex_t uhallibs::ipc::RobustMutex::mMutex |
|
private |
◆ mSessionActive
bool uhallibs::ipc::RobustMutex::mSessionActive |
|
private |
The documentation for this class was generated from the following files: