Peano
Loading...
Searching...
No Matches
Lock.cpp
Go to the documentation of this file.
1#include "tarch/Assertions.h"
4
5
6tarch::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
17 if (_lockIsAquired and _freeLockInDestructor) {
18 free();
19 }
20}
21
22
24 assertion( !_lockIsAquired );
25 _lockIsAquired = _semaphore.tryEnterCriticalSection();
26 return _lockIsAquired;
27}
28
29
31 assertion( !_lockIsAquired );
32 _semaphore.enterCriticalSection();
33 _lockIsAquired = true;
34}
35
36
38 assertion( _lockIsAquired or not _freeLockInDestructor );
39 _semaphore.leaveCriticalSection();
40 _lockIsAquired = false;
41}
42
#define assertion(expr)
Lock(tarch::multicore::BooleanSemaphore &semaphore, bool aquireLockImmediately=true, bool freeLockInDestructor=true)
Create lock around semaphore.
Definition Lock.cpp:6
void free()
Free the lock.
Definition Lock.cpp:37