-
Notifications
You must be signed in to change notification settings - Fork 13.7k
Commit ffe818a
Auto merge of #144465 - orlp:system-alloc-tls, r=Mark-Simulacrum
Allow the global allocator to use thread-local storage and std::thread::current()
Fixes #115209.
Currently the thread-local storage implementation uses the `Global` allocator if it needs to allocate memory in some places. This effectively means the global allocator can not use thread-local variables. This is a shame as an allocator is precisely one of the locations where you'd *really* want to use thread-locals. We also see that this lead to hacks such as #116402, where we detect re-entrance and abort.
So I've made the places where I could find allocation happening in the TLS implementation use the `System` allocator instead. I also applied this change to the storage allocated for a `Thread` handle so that it may be used care-free in the global allocator as well, for e.g. registering it to a central place or parking primitives.
r? `@joboet`File tree
9 files changed
+177
-42
lines changed- library
- core/src/alloc
- std/src
- sys/thread_local
- destructors
- key
- thread
- tests/ui/threads-sendsync
9 files changed
+177
-42
lines changedLines changed: 25 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
115 | 115 |
| |
116 | 116 |
| |
117 | 117 |
| |
118 | + | ||
119 | + | ||
120 | + | ||
121 | + | ||
122 | + | ||
123 | + | ||
124 | + | ||
125 | + | ||
126 | + | ||
127 | + | ||
128 | + | ||
129 | + | ||
130 | + | ||
131 | + | ||
132 | + | ||
133 | + | ||
134 | + | ||
135 | + | ||
136 | + | ||
137 | + | ||
138 | + | ||
139 | + | ||
140 | + | ||
141 | + | ||
142 | + | ||
118 | 143 |
| |
119 | 144 |
| |
120 | 145 |
| |
|
Lines changed: 8 additions & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
11 | 11 |
| |
12 | 12 |
| |
13 | 13 |
| |
14 | - | ||
14 | + | ||
15 | 15 |
| |
16 | 16 |
| |
17 | 17 |
| |
| |||
52 | 52 |
| |
53 | 53 |
| |
54 | 54 |
| |
55 | + | ||
56 | + | ||
57 | + | ||
58 | + | ||
59 | + | ||
60 | + | ||
61 | + | ||
55 | 62 |
| |
56 | 63 |
| |
57 | 64 |
| |
|
Lines changed: 5 additions & 10 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1 | + | ||
1 | 2 |
| |
2 | 3 |
| |
3 | 4 |
| |
4 | 5 |
| |
5 | - | ||
6 | + | ||
7 | + | ||
6 | 8 |
| |
7 | 9 |
| |
8 | - | ||
9 | - | ||
10 | - | ||
11 | - | ||
12 | - | ||
13 | - | ||
14 | - | ||
10 | + | ||
15 | 11 |
| |
16 | - | ||
17 | 12 |
| |
18 | 13 |
| |
19 | 14 |
| |
| |||
36 | 31 |
| |
37 | 32 |
| |
38 | 33 |
| |
39 | - | ||
34 | + | ||
40 | 35 |
| |
41 | 36 |
| |
42 | 37 |
| |
|
Lines changed: 5 additions & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
38 | 38 |
| |
39 | 39 |
| |
40 | 40 |
| |
41 | + | ||
41 | 42 |
| |
42 | 43 |
| |
43 | 44 |
| |
| |||
151 | 152 |
| |
152 | 153 |
| |
153 | 154 |
| |
154 | - | ||
155 | + | ||
156 | + | ||
157 | + | ||
158 | + | ||
155 | 159 |
| |
156 | 160 |
| |
157 | 161 |
| |
|
Lines changed: 8 additions & 4 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1 | 1 |
| |
2 | 2 |
| |
3 | + | ||
3 | 4 |
| |
4 | 5 |
| |
5 | 6 |
| |
| |||
95 | 96 |
| |
96 | 97 |
| |
97 | 98 |
| |
98 | - | ||
99 | - | ||
99 | + | ||
100 | + | ||
101 | + | ||
102 | + | ||
103 | + | ||
100 | 104 |
| |
101 | 105 |
| |
102 | 106 |
| |
| |||
114 | 118 |
| |
115 | 119 |
| |
116 | 120 |
| |
117 | - | ||
121 | + | ||
118 | 122 |
| |
119 | 123 |
| |
120 | 124 |
| |
| |||
133 | 137 |
| |
134 | 138 |
| |
135 | 139 |
| |
136 | - | ||
140 | + | ||
137 | 141 |
| |
138 | 142 |
| |
139 | 143 |
| |
|
Lines changed: 10 additions & 9 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
250 | 250 |
| |
251 | 251 |
| |
252 | 252 |
| |
253 | - | ||
254 | - | ||
255 | - | ||
256 | - | ||
257 | - | ||
258 | - | ||
259 | - | ||
260 | - | ||
261 | - | ||
253 | + | ||
254 | + | ||
255 | + | ||
256 | + | ||
257 | + | ||
258 | + | ||
259 | + | ||
260 | + | ||
261 | + | ||
262 | + | ||
262 | 263 |
| |
263 | 264 |
| |
264 | 265 |
| |
|
Lines changed: 6 additions & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
24 | 24 |
| |
25 | 25 |
| |
26 | 26 |
| |
27 | - | ||
27 | + | ||
28 | + | ||
29 | + | ||
30 | + | ||
28 | 31 |
| |
29 | 32 |
| |
30 | 33 |
| |
31 | 34 |
| |
32 | 35 |
| |
36 | + | ||
37 | + | ||
33 | 38 |
| |
34 | 39 |
| |
35 | 40 |
| |
|
Lines changed: 46 additions & 16 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
158 | 158 |
| |
159 | 159 |
| |
160 | 160 |
| |
161 | + | ||
161 | 162 |
| |
162 | 163 |
| |
163 | 164 |
| |
| |||
1231 | 1232 |
| |
1232 | 1233 |
| |
1233 | 1234 |
| |
1234 | - | ||
1235 | - | ||
1236 | - | ||
1235 | + | ||
1236 | + | ||
1237 | + | ||
1238 | + | ||
1239 | + | ||
1240 | + | ||
1241 | + | ||
1242 | + | ||
1243 | + | ||
1244 | + | ||
1245 | + | ||
1246 | + | ||
1247 | + | ||
1248 | + | ||
1249 | + | ||
1250 | + | ||
1251 | + | ||
1252 | + | ||
1253 | + | ||
1254 | + | ||
1255 | + | ||
1256 | + | ||
1257 | + | ||
1237 | 1258 |
| |
1238 | - | ||
1239 | - | ||
1240 | - | ||
1241 | - | ||
1242 | - | ||
1243 | - | ||
1259 | + | ||
1260 | + | ||
1261 | + | ||
1262 | + | ||
1263 | + | ||
1244 | 1264 |
| |
1245 | 1265 |
| |
1246 | - | ||
1247 | - | ||
1248 | - | ||
1266 | + | ||
1267 | + | ||
1268 | + | ||
1269 | + | ||
1270 | + | ||
1271 | + | ||
1272 | + | ||
1273 | + | ||
1249 | 1274 |
| |
1250 | 1275 |
| |
1251 | 1276 |
| |
| |||
1439 | 1464 |
| |
1440 | 1465 |
| |
1441 | 1466 |
| |
1442 | - | ||
1467 | + | ||
1468 | + | ||
1469 | + | ||
1470 | + | ||
1443 | 1471 |
| |
1444 | 1472 |
| |
1445 | 1473 |
| |
| |||
1452 | 1480 |
| |
1453 | 1481 |
| |
1454 | 1482 |
| |
1455 | - | ||
1483 | + | ||
1456 | 1484 |
| |
1457 | 1485 |
| |
1458 | 1486 |
| |
| |||
1610 | 1638 |
| |
1611 | 1639 |
| |
1612 | 1640 |
| |
1613 | - | ||
1641 | + | ||
1614 | 1642 |
| |
1615 | 1643 |
| |
1616 | 1644 |
| |
| |||
1632 | 1660 |
| |
1633 | 1661 |
| |
1634 | 1662 |
| |
1635 | - | ||
1663 | + | ||
1664 | + | ||
1665 | + | ||
1636 | 1666 |
| |
1637 | 1667 |
| |
1638 | 1668 |
| |
|
Lines changed: 64 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1 | + | ||
2 | + | ||
3 | + | ||
4 | + | ||
5 | + | ||
6 | + | ||
7 | + | ||
8 | + | ||
9 | + | ||
10 | + | ||
11 | + | ||
12 | + | ||
13 | + | ||
14 | + | ||
15 | + | ||
16 | + | ||
17 | + | ||
18 | + | ||
19 | + | ||
20 | + | ||
21 | + | ||
22 | + | ||
23 | + | ||
24 | + | ||
25 | + | ||
26 | + | ||
27 | + | ||
28 | + | ||
29 | + | ||
30 | + | ||
31 | + | ||
32 | + | ||
33 | + | ||
34 | + | ||
35 | + | ||
36 | + | ||
37 | + | ||
38 | + | ||
39 | + | ||
40 | + | ||
41 | + | ||
42 | + | ||
43 | + | ||
44 | + | ||
45 | + | ||
46 | + | ||
47 | + | ||
48 | + | ||
49 | + | ||
50 | + | ||
51 | + | ||
52 | + | ||
53 | + | ||
54 | + | ||
55 | + | ||
56 | + | ||
57 | + | ||
58 | + | ||
59 | + | ||
60 | + | ||
61 | + | ||
62 | + | ||
63 | + | ||
64 | + |
0 commit comments