Debian Codegraph @

vendor/Heap-Layers/heaps/threads/threadheap.h

raw symbols SCIP
1 /* -*- C++ -*- */cxx . . $ `<file>/vendor/Heap-Layers/heaps/threads/threadheap.h`/
2
3 #ifndef HL_THREADHEAP_H
4 #define HL_THREADHEAP_Hcxx . . $ `vendor/Heap-Layers/heaps/threads/threadheap.h:4:9`!
5
6 /*
7
8 Heap Layers: An Extensible Memory Allocation Infrastructure
9
10 Copyright (C) 2000-2020 by Emery Berger
11 http://www.emeryberger.com
12 [email protected]
13
14 Heap Layers is distributed under the terms of the Apache 2.0 license.
15
16 You may obtain a copy of the License at
17 http://www.apache.org/licenses/LICENSE-2.0
18
19 */
20
21 #include <assert.h>
22 #include <new>
23
24 #include "threads/cpuinfo.h"cxx . . $ `<file>/vendor/Heap-Layers/threads/cpuinfo.h`/
25
26 #if !defined(_WIN32)
27 #include <pthread.h>
28 #endif
29
30 /*
31
32 A ThreadHeap comprises NumHeaps "per-thread" heaps.
33
34 To pick a per-thread heap, the current thread id is hashed (mod NumHeaps).
35
36 malloc gets memory from its hashed per-thread heap.
37 free returns memory to its hashed per-thread heap.
38
39 (This allows the per-thread heap to determine the return
40 policy -- 'pure private heaps', 'private heaps with ownership',
41 etc.)
42
43 NB: We assume that the thread heaps are 'locked' as needed. */
44
45 namespace HLcxx . . $ HL/ {
46
47 template <int NumHeaps, class PerThreadHeap>
48 class ThreadHeapcxx . . $ HL/ThreadHeap# : public PerThreadHeap {
49 public:
50
51 enumcxx . . $ HL/ThreadHeap#$anonymous_type_0# { Alignmentcxx . . $ HL/ThreadHeap#Alignment. = PerThreadHeap::Alignment };
52
53 inline void * malloccxx . . $ HL/ThreadHeap#malloc(bfcfa4d6b7f7ef64). (size_t sz) {
54 auto tid = Modulocxx . . $ HL/Modulo#<NumHeaps>::mod (CPUInfocxx . . $ HL/CPUInfo#::getThreadIdcxx . . $ HL/CPUInfo#getThreadId(db52760e79bf9054).());
55 assertcxx . . $ `/usr/include/assert.h:50:10`! (tid >= 0);
56 assertcxx . . $ `/usr/include/assert.h:50:10`! (tid < NumHeaps);
57 return getHeapcxx . . $ HL/ThreadHeap#getHeap(ca3b85d8f00cb3cd).(tid)->malloc (sz);
58 }
59
60 inline void freecxx . . $ HL/ThreadHeap#free(5d22bdacc48458e8). (void * ptr) {
61 auto tid = Modulocxx . . $ HL/Modulo#<NumHeaps>::mod (CPUInfocxx . . $ HL/CPUInfo#::getThreadIdcxx . . $ HL/CPUInfo#getThreadId(db52760e79bf9054).());
62 assertcxx . . $ `/usr/include/assert.h:50:10`! (tid >= 0);
63 assertcxx . . $ `/usr/include/assert.h:50:10`! (tid < NumHeaps);
64 getHeapcxx . . $ HL/ThreadHeap#getHeap(ca3b85d8f00cb3cd).(tid)->free (ptr);
65 }
66
67 inline size_t getSizecxx . . $ HL/ThreadHeap#getSize(751e5d26f8574c32). (void * ptr) {
68 auto tid = Modulocxx . . $ HL/Modulo#<NumHeaps>::mod (CPUInfocxx . . $ HL/CPUInfo#::getThreadIdcxx . . $ HL/CPUInfo#getThreadId(db52760e79bf9054).());
69 assertcxx . . $ `/usr/include/assert.h:50:10`! (tid >= 0);
70 assertcxx . . $ `/usr/include/assert.h:50:10`! (tid < NumHeaps);
71 return getHeapcxx . . $ HL/ThreadHeap#getHeap(ca3b85d8f00cb3cd).(tid)->getSize (ptr);
72 }
73
74
75 private:
76
77 // Access the given heap within the buffer.
78 inline PerThreadHeap * getHeapcxx . . $ HL/ThreadHeap#getHeap(ca3b85d8f00cb3cd). (unsigned int index) {
79 int ind = (int) index;
80 assertcxx . . $ `/usr/include/assert.h:50:10`! (ind >= 0);
81 assertcxx . . $ `/usr/include/assert.h:50:10`! (ind < NumHeaps);
82 return &cxx . . $ std/`operator&`(3fbb01592cd53f2a).ptHeapscxx . . $ HL/ThreadHeap#ptHeaps.[ind];
83 }
84
85 PerThreadHeap ptHeapscxx . . $ HL/ThreadHeap#ptHeaps.[NumHeaps];
86
87 };
88
89 }
90
91
92 #endif