File tree Expand file tree Collapse file tree 3 files changed +92
-31
lines changed
src/snmalloc/backend_helpers Expand file tree Collapse file tree 3 files changed +92
-31
lines changed Original file line number Diff line number Diff line change 22
33#include " ../ds/ds.h"
44#include " empty_range.h"
5+ #include " lockrange.h"
6+ #include " staticrange.h"
57
68namespace snmalloc
79{
@@ -12,36 +14,7 @@ namespace snmalloc
1214 struct GlobalRange
1315 {
1416 template <typename ParentRange = EmptyRange<>>
15- class Type : public StaticParent <ParentRange>
16- {
17- using StaticParent<ParentRange>::parent;
18-
19- /* *
20- * This is infrequently used code, a spin lock simplifies the code
21- * considerably, and should never be on the fast path.
22- */
23- SNMALLOC_REQUIRE_CONSTINIT static inline FlagWord spin_lock{};
24-
25- public:
26- static constexpr bool Aligned = ParentRange::Aligned;
27-
28- static constexpr bool ConcurrencySafe = true ;
29-
30- using ChunkBounds = typename ParentRange::ChunkBounds;
31-
32- constexpr Type () = default;
33-
34- CapPtr<void , ChunkBounds> alloc_range (size_t size)
35- {
36- FlagLock lock (spin_lock);
37- return parent.alloc_range (size);
38- }
39-
40- void dealloc_range (CapPtr<void , ChunkBounds> base, size_t size)
41- {
42- FlagLock lock (spin_lock);
43- parent.dealloc_range (base, size);
44- }
45- };
17+ class Type : public Pipe <ParentRange, LockRange, StaticRange>
18+ {};
4619 };
4720} // namespace snmalloc
Original file line number Diff line number Diff line change 1+ #pragma once
2+
3+ #include " ../ds/ds.h"
4+ #include " empty_range.h"
5+
6+ namespace snmalloc
7+ {
8+ /* *
9+ * Protect the ParentRange with a spin lock.
10+ */
11+ struct LockRange
12+ {
13+ template <typename ParentRange = EmptyRange<>>
14+ class Type : public ContainsParent <ParentRange>
15+ {
16+ using ContainsParent<ParentRange>::parent;
17+
18+ /* *
19+ * This is infrequently used code, a spin lock simplifies the code
20+ * considerably, and should never be on the fast path.
21+ */
22+ FlagWord spin_lock{};
23+
24+ public:
25+ static constexpr bool Aligned = ParentRange::Aligned;
26+
27+ using ChunkBounds = typename ParentRange::ChunkBounds;
28+
29+ static constexpr bool ConcurrencySafe = true ;
30+
31+ constexpr Type () = default;
32+
33+ CapPtr<void , ChunkBounds> alloc_range (size_t size)
34+ {
35+ FlagLock lock (spin_lock);
36+ return parent.alloc_range (size);
37+ }
38+
39+ void dealloc_range (CapPtr<void , ChunkBounds> base, size_t size)
40+ {
41+ FlagLock lock (spin_lock);
42+ parent.dealloc_range (base, size);
43+ }
44+ };
45+ };
46+ } // namespace snmalloc
Original file line number Diff line number Diff line change 1+ #pragma once
2+
3+ #include " ../ds/ds.h"
4+ #include " empty_range.h"
5+
6+ namespace snmalloc
7+ {
8+ /* *
9+ * Makes the supplied ParentRange into a global variable.
10+ */
11+ struct StaticRange
12+ {
13+ template <typename ParentRange = EmptyRange<>>
14+ class Type : public StaticParent <ParentRange>
15+ {
16+ using StaticParent<ParentRange>::parent;
17+
18+ public:
19+ static constexpr bool Aligned = ParentRange::Aligned;
20+
21+ static_assert (
22+ ParentRange::ConcurrencySafe,
23+ " StaticRange requires a concurrency safe parent." );
24+
25+ static constexpr bool ConcurrencySafe = true ;
26+
27+ using ChunkBounds = typename ParentRange::ChunkBounds;
28+
29+ constexpr Type () = default;
30+
31+ CapPtr<void , ChunkBounds> alloc_range (size_t size)
32+ {
33+ return parent.alloc_range (size);
34+ }
35+
36+ void dealloc_range (CapPtr<void , ChunkBounds> base, size_t size)
37+ {
38+ parent.dealloc_range (base, size);
39+ }
40+ };
41+ };
42+ } // namespace snmalloc
You can’t perform that action at this time.
0 commit comments