TinyRobotics
Loading...
Searching...
No Matches
src
TinyRobotics
concurrency
LockGuard.h
1
#
pragma
once
2
#
include
"TinyRobotics/utils/Config.h"
3
#
include
"Mutex.h"
4
5
namespace
tinyrobotics {
6
7
8
/**
9
* @class LockGuard
10
* @ingroup concurrency
11
* @brief RAII implementaion using a Mutex: Only a few microcontrollers provide
12
* lock guards, so I decided to roll my own solution where we can just use a
13
* dummy Mutex implementation that does nothing for the cases where this is not
14
* needed.
15
* @author Phil Schatzmann
16
*/
17
18
class
LockGuard
{
19
public
:
20
LockGuard(
MutexBase
&mutex) {
21
p_mutex = &mutex;
22
p_mutex->lock();
23
}
24
25
LockGuard(
MutexBase
*mutex) {
26
p_mutex = mutex;
27
if
(p_mutex !=
nullptr
) p_mutex->lock();
28
}
29
30
~LockGuard() {
31
if
(p_mutex !=
nullptr
) p_mutex->unlock();
32
}
33
34
protected
:
35
MutexBase
*p_mutex =
nullptr
;
36
};
37
38
39
}
// namespace tinyrobotics
tinyrobotics::LockGuard
RAII implementaion using a Mutex: Only a few microcontrollers provide lock guards,...
Definition:
LockGuard.h:18
tinyrobotics::MutexBase
Empty Mutex implementation which does nothing.
Definition:
Mutex.h:18
Generated by
1.9.6