DUNE-DAQ
DUNE Trigger and Data Acquisition software
Toggle main menu visibility
Loading...
Searching...
No Matches
dunedaq
sourcecode
uhallibs
src
RobustMutex.cpp
Go to the documentation of this file.
1
#include "
uhallibs/ipc/RobustMutex.hpp
"
2
3
#include <cstring>
4
#include "uhal/log/log.hpp"
5
6
7
namespace
uhallibs
{
8
namespace
ipc
{
9
10
RobustMutex::RobustMutex
() :
mCount
(0),
mSessionActive
(false) {
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
}
45
46
RobustMutex::~RobustMutex
() {}
47
48
void
RobustMutex::lock
() {
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
}
60
61
void
RobustMutex::unlock
() {
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
}
67
68
uint64_t
RobustMutex::getCounter
()
const
{
return
mCount
; }
69
70
bool
RobustMutex::isActive
()
const
{
return
mSessionActive
; }
71
72
void
RobustMutex::startSession
() {
73
mCount
++;
74
mSessionActive
=
true
;
75
}
76
77
void
RobustMutex::endSession
() {
mSessionActive
=
false
; }
78
79
}
// namespace ipc
80
}
// namespace uhal
RobustMutex.hpp
uhallibs::ipc::RobustMutex::lock
void lock()
Definition
RobustMutex.cpp:48
uhallibs::ipc::RobustMutex::~RobustMutex
~RobustMutex()
Definition
RobustMutex.cpp:46
uhallibs::ipc::RobustMutex::getCounter
uint64_t getCounter() const
Definition
RobustMutex.cpp:68
uhallibs::ipc::RobustMutex::RobustMutex
RobustMutex()
Definition
RobustMutex.cpp:10
uhallibs::ipc::RobustMutex::isActive
bool isActive() const
Definition
RobustMutex.cpp:70
uhallibs::ipc::RobustMutex::startSession
void startSession()
Definition
RobustMutex.cpp:72
uhallibs::ipc::RobustMutex::unlock
void unlock()
Definition
RobustMutex.cpp:61
uhallibs::ipc::RobustMutex::mSessionActive
bool mSessionActive
Definition
RobustMutex.hpp:42
uhallibs::ipc::RobustMutex::mCount
uint64_t mCount
Definition
RobustMutex.hpp:41
uhallibs::ipc::RobustMutex::mMutex
pthread_mutex_t mMutex
Definition
RobustMutex.hpp:40
uhallibs::ipc::RobustMutex::endSession
void endSession()
Definition
RobustMutex.cpp:77
uhallibs::ipc
Definition
RobustMutex.hpp:11
uhallibs
Definition
formatters.hpp:9
Generated on
for DUNE-DAQ by
1.17.0