Debian Codegraph @

vendor/Heap-Layers/locks/recursivelock.h

raw symbols SCIP
1 /* -*- C++ -*- */cxx . . $ `<file>/vendor/Heap-Layers/locks/recursivelock.h`/
2
3 /*
4
5 Heap Layers: An Extensible Memory Allocation Infrastructure
6
7 Copyright (C) 2000-2020 by Emery Berger
8 http://www.emeryberger.com
9 [email protected]
10
11 Heap Layers is distributed under the terms of the Apache 2.0 license.
12
13 You may obtain a copy of the License at
14 http://www.apache.org/licenses/LICENSE-2.0
15
16 */
17
18 #ifndef HL_RECURSIVELOCK_H
19 #define HL_RECURSIVELOCK_Hcxx . . $ `vendor/Heap-Layers/locks/recursivelock.h:19:9`!
20
21 #include <cassert>
22 #include "threads/cpuinfo.h"cxx . . $ `<file>/vendor/Heap-Layers/threads/cpuinfo.h`/
23
24 /**
25 * @class RecursiveLockType
26 * @brief Implements a recursive lock using some base lock representation.
27 * @param BaseLock The base lock representation.
28 */
29
30 namespace HLcxx . . $ HL/ {
31
32 template <class BaseLock>
33 class RecursiveLockTypecxx . . $ HL/RecursiveLockType# : public BaseLock {
34 public:
35
36 inline RecursiveLockTypecxx . . $ HL/RecursiveLockType#`RecursiveLockType<BaseLock>`(49f6e7a06ebc5aa8). (void)
37 : _tidcxx . . $ HL/RecursiveLockType#_tid. (-1),
38 _recursiveDepthcxx . . $ HL/RecursiveLockType#_recursiveDepth. (0)
39 {}
40
41 inline void lockcxx . . $ HL/RecursiveLockType#lock(49f6e7a06ebc5aa8).() {
42 auto currthread = CPUInfocxx . . $ HL/CPUInfo#::getThreadIdcxx . . $ HL/CPUInfo#getThreadId(db52760e79bf9054).();
43 if (_tidcxx . . $ HL/RecursiveLockType#_tid. == currthread) {
44 _recursiveDepthcxx . . $ HL/RecursiveLockType#_recursiveDepth.++;
45 } else {
46 BaseLock::lock();
47 _tidcxx . . $ HL/RecursiveLockType#_tid. = currthread;
48 _recursiveDepthcxx . . $ HL/RecursiveLockType#_recursiveDepth.++;
49 }
50 }
51
52 inline void unlockcxx . . $ HL/RecursiveLockType#unlock(49f6e7a06ebc5aa8). (void) {
53 auto currthread = (int) CPUInfocxx . . $ HL/CPUInfo#::getThreadIdcxx . . $ HL/CPUInfo#getThreadId(db52760e79bf9054).();
54 if (_tidcxx . . $ HL/RecursiveLockType#_tid. == currthread) {
55 _recursiveDepthcxx . . $ HL/RecursiveLockType#_recursiveDepth.--;
56 if (_recursiveDepthcxx . . $ HL/RecursiveLockType#_recursiveDepth. == 0) {
57 _tidcxx . . $ HL/RecursiveLockType#_tid. = -1;
58 BaseLock::unlock();
59 }
60 } else {
61 // We tried to unlock it but we didn't lock it!
62 // This should never happen.
63 assertcxx . . $ `/usr/include/assert.h:50:10`! (0);
64 abortcxx . . $ abort(8df32a62017fbbf6).();
65 }
66 }
67
68 private:
69 int _tidcxx . . $ HL/RecursiveLockType#_tid.; /// The lock owner's thread id. -1 if unlocked.
70 int _recursiveDepthcxx . . $ HL/RecursiveLockType#_recursiveDepth.; /// The recursion depth of the lock.
71 };
72
73 }
74
75
76
77
78 #endif