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

Fixes #308: Remove useless fences on chunk's prev field accesses #309

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ final R producerChunkForIndex(
{
// prev cannot be null, because the consumer cannot null it without consuming the element for which we are
// trying to get the chunk.
currentChunk = currentChunk.lvPrev();
currentChunk = currentChunk.lpPrev();
assert currentChunk != null;
}
assert currentChunk.lvIndex() == requiredChunkIndex;
Expand Down Expand Up @@ -355,7 +355,7 @@ private R newOrPooledChunk(R prevChunk, long nextChunkIndex)
{
// single-writer: prevChunk::index == nextChunkIndex is protecting it
assert newChunk.lvIndex() < prevChunk.lvIndex();
newChunk.soPrev(prevChunk);
newChunk.spPrev(prevChunk);
// index set is releasing prev, allowing other pending offers to continue
newChunk.soIndex(nextChunkIndex);
}
Expand All @@ -374,7 +374,7 @@ final void moveToNextConsumerChunk(R cChunk, R next)
{
// avoid GC nepotism
cChunk.soNext(null);
next.soPrev(null);
next.spPrev(null);
// no need to cChunk.soIndex(NOT_USED)
if (cChunk.isPooled())
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,20 @@ class MpUnboundedXaddChunk<R,E>
{
final static int NOT_USED = -1;

private static final long PREV_OFFSET = fieldOffset(MpUnboundedXaddChunk.class, "prev");
private static final long NEXT_OFFSET = fieldOffset(MpUnboundedXaddChunk.class, "next");
private static final long INDEX_OFFSET = fieldOffset(MpUnboundedXaddChunk.class, "index");

private final boolean pooled;
private final E[] buffer;

private volatile R prev;
private R prev;
private volatile long index;
private volatile R next;
MpUnboundedXaddChunk(long index, R prev, int size, boolean pooled)
{
buffer = allocateRefArray(size);
// next is null
soPrev(prev);
spPrev(prev);
spIndex(index);
this.pooled = pooled;
}
Expand Down Expand Up @@ -60,14 +59,14 @@ final void soNext(R value)
UNSAFE.putOrderedObject(this, NEXT_OFFSET, value);
}

final R lvPrev()
final R lpPrev()
{
return prev;
return this.prev;
}

final void soPrev(R value)
final void spPrev(R value)
{
UNSAFE.putObject(this, PREV_OFFSET, value);
this.prev = value;
}

final void soElement(int index, E e)
Expand Down