Peano
Loading...
Searching...
No Matches
Lock.cpp
Go to the documentation of this file.
1
#include "
tarch/Assertions.h
"
2
#include "
tarch/multicore/Lock.h
"
3
#include "
tarch/multicore/BooleanSemaphore.h
"
4
5
6
tarch::multicore::Lock::Lock
(
tarch::multicore::BooleanSemaphore
& semaphore,
bool
aquireLockImmediately,
bool
freeLockInDestructor ):
7
_semaphore(semaphore),
8
_lockIsAquired(false),
9
_freeLockInDestructor(freeLockInDestructor) {
10
if
(aquireLockImmediately) {
11
lock
();
12
}
13
}
14
15
16
tarch::multicore::Lock::~Lock
() {
17
if
(_lockIsAquired and _freeLockInDestructor) {
18
free();
19
}
20
}
21
22
23
bool
tarch::multicore::Lock::tryLock
() {
24
assertion
( !_lockIsAquired );
25
_lockIsAquired = _semaphore.tryEnterCriticalSection();
26
return
_lockIsAquired;
27
}
28
29
30
void
tarch::multicore::Lock::lock
() {
31
assertion
( !_lockIsAquired );
32
_semaphore.enterCriticalSection();
33
_lockIsAquired =
true
;
34
}
35
36
37
void
tarch::multicore::Lock::free
() {
38
assertion
( _lockIsAquired or not _freeLockInDestructor );
39
_semaphore.leaveCriticalSection();
40
_lockIsAquired =
false
;
41
}
42
Assertions.h
assertion
#define assertion(expr)
Definition
Assertions.h:1017
tarch::multicore::BooleanSemaphore
Definition
BooleanSemaphore.h:21
tarch::multicore::Lock::Lock
Lock(tarch::multicore::BooleanSemaphore &semaphore, bool aquireLockImmediately=true, bool freeLockInDestructor=true)
Create lock around semaphore.
Definition
Lock.cpp:6
tarch::multicore::Lock::free
void free()
Free the lock.
Definition
Lock.cpp:37
tarch::multicore::Lock::tryLock
bool tryLock()
Definition
Lock.cpp:23
tarch::multicore::Lock::lock
void lock()
Definition
Lock.cpp:30
tarch::multicore::Lock::~Lock
~Lock()
Definition
Lock.cpp:16
BooleanSemaphore.h
Lock.h
src
tarch
multicore
Lock.cpp
Generated on Fri Apr 11 2025 10:18:08 for Peano by
1.10.0