-
Notifications
You must be signed in to change notification settings - Fork 118
Conditional range #617
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Conditional range #617
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
f758e91
Make a conditional range
mjp41 e908fee
Some comments.
mjp41 b5613eb
Added a constant.
mjp41 c35b55c
Clangformat
mjp41 5bba5e2
Remove unused method.
mjp41 30887f4
Changes from testing.
mjp41 a834dad
Code review
mjp41 52fcbe9
Fix equality of types test.
mjp41 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,78 @@ | ||
#pragma once | ||
#include "../pal/pal.h" | ||
#include "empty_range.h" | ||
#include "range_helpers.h" | ||
|
||
namespace snmalloc | ||
{ | ||
template<typename OptionalRange> | ||
struct StaticConditionalRange | ||
{ | ||
// This is a range that can bypass the OptionalRange if it is disabled. | ||
// Disabling is global, and not local. | ||
// This is used to allow disabling thread local buddy allocators when the | ||
// initial fixed size heap is small. | ||
// | ||
// The range builds a more complex parent | ||
// Pipe<ParentRange, OptionalRange> | ||
// and uses the ancestor functions to bypass the OptionalRange if the flag | ||
// has been set. | ||
template<typename ParentRange> | ||
class Type : public ContainsParent<Pipe<ParentRange, OptionalRange>> | ||
{ | ||
// This contains connects the optional range to the parent range. | ||
using ActualParentRange = Pipe<ParentRange, OptionalRange>; | ||
|
||
using ContainsParent<ActualParentRange>::parent; | ||
|
||
// Global flag specifying if the optional range should be disabled. | ||
static inline bool disable_range_{false}; | ||
|
||
public: | ||
// Both parent and grandparent must be aligned for this range to be | ||
// aligned. | ||
static constexpr bool Aligned = | ||
ActualParentRange::Aligned && ParentRange::Aligned; | ||
|
||
// Both parent and grandparent must be aligned for this range to be | ||
// concurrency safe. | ||
static constexpr bool ConcurrencySafe = | ||
ActualParentRange::ConcurrencySafe && ParentRange::ConcurrencySafe; | ||
|
||
using ChunkBounds = typename ActualParentRange::ChunkBounds; | ||
nwf-msr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
static_assert( | ||
std::is_same_v<ChunkBounds, typename ParentRange::ChunkBounds>, | ||
"Grandparent and optional parent range chunk bounds must be equal"); | ||
|
||
constexpr Type() = default; | ||
|
||
CapPtr<void, ChunkBounds> alloc_range(size_t size) | ||
{ | ||
if (disable_range_) | ||
{ | ||
// Use ancestor to bypass the optional range. | ||
return this->template ancestor<ParentRange>()->alloc_range(size); | ||
} | ||
|
||
return parent.alloc_range(size); | ||
} | ||
|
||
void dealloc_range(CapPtr<void, ChunkBounds> base, size_t size) | ||
{ | ||
if (disable_range_) | ||
{ | ||
// Use ancestor to bypass the optional range. | ||
this->template ancestor<ParentRange>()->dealloc_range(base, size); | ||
return; | ||
} | ||
parent.dealloc_range(base, size); | ||
} | ||
|
||
static void disable_range() | ||
{ | ||
disable_range_ = true; | ||
} | ||
}; | ||
}; | ||
} // namespace snmalloc |
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've nothing to add here except to quote Hackers:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now I need to watch "Hackers" ;)