-
Notifications
You must be signed in to change notification settings - Fork 112
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add indirect range The ranges currently either completely own the parent range, or it is a static and thus completely shared. The indirect range allows sharing without it being global. Co-authored-by: Nathaniel Filardo <nfilardo@microsoft.com>
- Loading branch information
Showing
3 changed files
with
86 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#pragma once | ||
|
||
#include "../ds/ds.h" | ||
#include "empty_range.h" | ||
|
||
namespace snmalloc | ||
{ | ||
/** | ||
* Stores a references to the parent range so that it can be shared | ||
* without `static` scope. | ||
* | ||
* This could be used to allow multiple allocators on a single region of | ||
* memory. | ||
*/ | ||
struct IndirectRange | ||
{ | ||
template<typename ParentRange = EmptyRange<>> | ||
class Type : public RefParent<ParentRange> | ||
{ | ||
using RefParent<ParentRange>::parent; | ||
|
||
public: | ||
static constexpr bool Aligned = ParentRange::Aligned; | ||
|
||
static_assert( | ||
ParentRange::ConcurrencySafe, | ||
"IndirectRange requires a concurrency safe parent."); | ||
|
||
static constexpr bool ConcurrencySafe = true; | ||
|
||
using ChunkBounds = typename ParentRange::ChunkBounds; | ||
|
||
constexpr Type() = default; | ||
|
||
CapPtr<void, ChunkBounds> alloc_range(size_t size) | ||
{ | ||
return parent->alloc_range(size); | ||
} | ||
|
||
void dealloc_range(CapPtr<void, ChunkBounds> base, size_t size) | ||
{ | ||
parent->dealloc_range(base, size); | ||
} | ||
|
||
/** | ||
* Points the parent reference to the given range. | ||
*/ | ||
void set_parent(ParentRange* p) | ||
{ | ||
parent = p; | ||
} | ||
}; | ||
}; | ||
} // namespace snmalloc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters