Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

edi33416
Copy link
Contributor

No description provided.

@dlang-bot
Copy link
Contributor

dlang-bot commented Feb 21, 2018

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 verify that your PR follows this checklist:

  • My PR is fully covered with tests (you can see the annotated coverage diff directly on GitHub with CodeCov's browser extension
  • My PR is as minimal as possible (smaller, focused PRs are easier to review than big ones)
  • I have provided a detailed rationale explaining my changes
  • New or modified functions have Ddoc comments (with Params: and Returns:)

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 references

Your 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 locally

If 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;
Copy link
Member

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);
Copy link
Member

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))
Copy link
Member

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;
Copy link
Contributor Author

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.

@edi33416
Copy link
Contributor Author

@jercaianu

@edi33416
Copy link
Contributor Author

I've moved the parent() logic inside the mixin template Impl as this also needs to infer the shared attribute.

Copy link
Contributor

@jercaianu jercaianu left a 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()
Copy link
Contributor

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;
Copy link
Contributor

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
Copy link
Contributor

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.

@edi33416 edi33416 force-pushed the aff_all_rcshared branch 2 times, most recently from b03976f to 25c65ab Compare April 25, 2018 22:57
@n8sh n8sh added the 72h no objection -> merge The PR will be merged if there are no objections raised. label Apr 26, 2018
@edi33416
Copy link
Contributor Author

@n8sh could you have another look at the code? Changed sync to use only one variable

@n8sh n8sh removed the 72h no objection -> merge The PR will be merged if there are no objections raised. label Jun 13, 2018
(&wrapProcAllocatorObject))();
_parent = fn();
}
parentUnlock(_lockVar);
Copy link
Member

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.

@RazvanN7
Copy link
Collaborator

@edi33416 What is the state of this PR? Should we pull it in?

@LightBender LightBender added the Salvage This PR needs work, but we want to keep it and it can be salvaged. label Oct 27, 2024
@LightBender
Copy link
Contributor

@thewilsonator if can rebase this and get it in we'll take it.
@edi33416 if you want to resurrect this we'll take it in.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
allocators Needs Rebase Salvage This PR needs work, but we want to keep it and it can be salvaged. stalled
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants