Commit f3d63c4
committed
fix: guard-free recycling frame allocator, survives thread-exit teardown
Rework the recycling frame allocator so its per-thread pool is
trivially destructible and constant-initialized. This removes the
guard variable the compiler placed on the thread_local in local()
(checked on every allocate/free), making the hot path a bare TLS
load, and it fixes a thread-exit crash.
Previously the pool held a non-trivial destructor that drained its
cached blocks at thread exit. On MinGW toolchains that thread_local
teardown can run twice, the second time on the already freed pool
block, so the drain read a poisoned bucket count and indexed wild
(observed as an IOCP-thread heap corruption once multi-threaded
io_context tests began exiting worker threads, surfaced under gcov).
With no pool destructor, that teardown cannot double-run. Cached
blocks are reclaimed off the hot path instead: per thread by a
janitor armed once (from the slow paths, and behind a guard-free
flag in deallocate_fast) whose destructor drains via local() and is
naturally idempotent (a second run finds empty buckets) and never
touches its own storage; and the global pool by its holder's
destructor at process exit. Adopts the guard-free allocator design
from perf/frame-alloc-guard-free. Adds a thread-exit teardown
regression test.1 parent 0d3dd90 commit f3d63c4
3 files changed
Lines changed: 120 additions & 64 deletions
File tree
- include/boost/capy/ex
- src/ex
- test/unit/ex
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
36 | | - | |
37 | | - | |
38 | | - | |
39 | | - | |
40 | | - | |
41 | | - | |
42 | | - | |
43 | | - | |
44 | | - | |
45 | 36 | | |
46 | 37 | | |
47 | 38 | | |
| |||
80 | 71 | | |
81 | 72 | | |
82 | 73 | | |
83 | | - | |
| 74 | + | |
84 | 75 | | |
85 | 76 | | |
86 | 77 | | |
| |||
114 | 105 | | |
115 | 106 | | |
116 | 107 | | |
117 | | - | |
118 | | - | |
119 | | - | |
120 | | - | |
121 | | - | |
122 | | - | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
123 | 114 | | |
124 | 115 | | |
125 | 116 | | |
| |||
134 | 125 | | |
135 | 126 | | |
136 | 127 | | |
137 | | - | |
138 | | - | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
139 | 133 | | |
140 | | - | |
141 | | - | |
142 | | - | |
143 | | - | |
144 | | - | |
| 134 | + | |
145 | 135 | | |
146 | 136 | | |
147 | 137 | | |
148 | 138 | | |
149 | 139 | | |
150 | 140 | | |
151 | 141 | | |
152 | | - | |
153 | | - | |
154 | | - | |
155 | | - | |
156 | | - | |
157 | | - | |
158 | | - | |
159 | 142 | | |
160 | 143 | | |
161 | | - | |
| 144 | + | |
162 | 145 | | |
163 | 146 | | |
164 | 147 | | |
| |||
175 | 158 | | |
176 | 159 | | |
177 | 160 | | |
178 | | - | |
179 | | - | |
180 | | - | |
181 | | - | |
182 | | - | |
183 | | - | |
184 | | - | |
185 | | - | |
186 | 161 | | |
187 | 162 | | |
188 | | - | |
| 163 | + | |
189 | 164 | | |
190 | 165 | | |
191 | 166 | | |
| |||
194 | 169 | | |
195 | 170 | | |
196 | 171 | | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
197 | 181 | | |
198 | 182 | | |
199 | 183 | | |
200 | 184 | | |
201 | 185 | | |
202 | 186 | | |
203 | 187 | | |
204 | | - | |
205 | | - | |
206 | | - | |
207 | | - | |
208 | | - | |
209 | | - | |
210 | | - | |
211 | | - | |
212 | | - | |
213 | 188 | | |
214 | | - | |
215 | | - | |
216 | | - | |
217 | | - | |
218 | | - | |
219 | | - | |
| 189 | + | |
220 | 190 | | |
221 | | - | |
222 | | - | |
223 | | - | |
224 | | - | |
225 | 191 | | |
226 | | - | |
| 192 | + | |
227 | 193 | | |
228 | 194 | | |
229 | 195 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| 12 | + | |
| 13 | + | |
12 | 14 | | |
13 | 15 | | |
14 | 16 | | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
15 | 21 | | |
16 | 22 | | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
17 | 43 | | |
18 | 44 | | |
19 | 45 | | |
20 | | - | |
21 | | - | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
22 | 65 | | |
23 | 66 | | |
24 | 67 | | |
25 | 68 | | |
26 | 69 | | |
27 | | - | |
28 | | - | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
29 | 78 | | |
30 | 79 | | |
31 | 80 | | |
32 | 81 | | |
33 | 82 | | |
34 | 83 | | |
| 84 | + | |
35 | 85 | | |
36 | 86 | | |
37 | 87 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| 14 | + | |
14 | 15 | | |
15 | 16 | | |
16 | 17 | | |
| |||
69 | 70 | | |
70 | 71 | | |
71 | 72 | | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
72 | 111 | | |
73 | 112 | | |
74 | 113 | | |
75 | 114 | | |
76 | 115 | | |
| 116 | + | |
77 | 117 | | |
78 | 118 | | |
79 | 119 | | |
| |||
0 commit comments