-
-
Notifications
You must be signed in to change notification settings - Fork 700
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
Make AffixAllocator take into account RCISharedAllocator #6205
base: master
Are you sure you want to change the base?
Conversation
Thanks for your pull request and interest in making D better, @edi33416! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
Please see CONTRIBUTING.md for more information. If you have addressed all reviews or aren't sure how to proceed, don't hesitate to ping us with a simple comment. Bugzilla referencesYour PR doesn't reference any Bugzilla issue. If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog. Testing this PR locallyIf you don't have a local development environment setup, you can use Digger to test this PR: dub fetch digger
dub run digger -- build "master + phobos#6205" |
|
||
@system unittest | ||
{ | ||
import std.experimental.allocator : RCISharedAllocator, processAllocator; |
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.
processAllocator
isn't used here ;-)
|
||
AffixAllocator!(RCISharedAllocator, uint) a; | ||
auto buf = a.allocate(42); | ||
assert(buf.length == 42); |
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.
Any chance we can replace the processAllocator
with something like this?
auto prevAllocator = processAllocator;
scope(exit) processAllocator = prevAllocator;
alias SCAlloc = StatsCollector!(Mallocator, Options.bytesUsed);
SCAlloc statsCollectorAlloc;
processAllocator = allocatorObject(statsCollectorAlloc);
...
assert(statsCollectorAlloc.bytesUsed == 100);
@@ -69,11 +70,21 @@ struct AffixAllocator(Allocator, Prefix, Suffix = void) | |||
static if (stateSize!Allocator) | |||
{ | |||
Allocator _parent; | |||
static if (is(Allocator == RCIAllocator)) | |||
static if (is(Allocator == RCIAllocator) || is(Allocator == RCISharedAllocator)) |
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.
This behavior isn't mentioned in the docs above...
@@ -69,11 +70,21 @@ struct AffixAllocator(Allocator, Prefix, Suffix = void) | |||
static if (stateSize!Allocator) | |||
{ | |||
Allocator _parent; |
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 think this, Allocator _parent
, should be made private as we want the user to use the parent()
method.
41bf8dd
to
d4cf839
Compare
I've moved the |
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.
Aside from some minor comments, great job!
if (_parent.isNull) _parent = theAllocator; | ||
assert(alignment <= _parent.alignment); | ||
return _parent; | ||
Allocator parent() |
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.
Does this need to return by value?
Shouldn't it return a reference to the parent?
} | ||
else | ||
{ | ||
_parent = processAllocator; |
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.
Since parent can be called by multiple threads, is this assignment guaranteed to be thread safe?
@@ -520,3 +540,30 @@ struct AffixAllocator(Allocator, Prefix, Suffix = void) | |||
static assert(is(typeof(a.allocate) == shared)); | |||
assert(buf.length == 10); | |||
} | |||
|
|||
@system unittest |
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 think it would be a good idea to also have a test in which we access this from multiple threads.
d4cf839
to
5877da2
Compare
b03976f
to
25c65ab
Compare
25c65ab
to
8076b6f
Compare
@n8sh could you have another look at the code? Changed sync to use only one variable |
(&wrapProcAllocatorObject))(); | ||
_parent = fn(); | ||
} | ||
parentUnlock(_lockVar); |
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.
To avoid deadlock instead put scope(exit) parentUnlock(_lockVar);
right after the lock is acquired.
@edi33416 What is the state of this PR? Should we pull it in? |
@thewilsonator if can rebase this and get it in we'll take it. |
No description provided.