Skip to content

Commit

Permalink
Code tidyup
Browse files Browse the repository at this point in the history
  • Loading branch information
nitsanw committed Jan 31, 2019
1 parent cb6cb00 commit 061fce0
Showing 1 changed file with 10 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@

import java.util.Queue;

import static org.jctools.util.UnsafeAccess.UNSAFE;
import static org.jctools.util.UnsafeAccess.fieldOffset;
import static org.jctools.util.UnsafeRefArrayAccess.lvElement;
import static org.jctools.util.UnsafeRefArrayAccess.soElement;

abstract class FFBufferL1Pad<E> extends ConcurrentCircularArrayQueue<E>
{
Expand Down Expand Up @@ -86,13 +89,13 @@ public FFBuffer(final int capacity)
@Override
public final long lvConsumerIndex()
{
return UnsafeAccess.UNSAFE.getLongVolatile(this, C_INDEX_OFFSET);
return UNSAFE.getLongVolatile(this, C_INDEX_OFFSET);
}

@Override
public final long lvProducerIndex()
{
return UnsafeAccess.UNSAFE.getLongVolatile(this, P_INDEX_OFFSET);
return UNSAFE.getLongVolatile(this, P_INDEX_OFFSET);
}

@Override
Expand All @@ -106,11 +109,11 @@ public boolean offer(final E e)
final E[] lb = buffer;
final long t = pIndex;
final long offset = calcElementOffset(t);
if (null != UnsafeRefArrayAccess.lvElement(lb, offset))
if (null != lvElement(lb, offset))
{ // read acquire
return false;
}
UnsafeRefArrayAccess.soElement(lb, offset, e); // write release
soElement(lb, offset, e); // write release
pIndex = t + 1;
return true;
}
Expand All @@ -121,12 +124,12 @@ public E poll()
long cIndex = this.cIndex;
final long offset = calcElementOffset(cIndex);
final E[] lb = buffer;
final E e = UnsafeRefArrayAccess.lvElement(lb, offset); // write acquire
final E e = lvElement(lb, offset); // write acquire
if (null == e)
{
return null;
}
UnsafeRefArrayAccess.soElement(lb, offset, null); // read release
soElement(lb, offset, null); // read release
this.cIndex = cIndex + 1;
return e;
}
Expand All @@ -135,7 +138,7 @@ public E poll()
public E peek()
{
long currentHead = lvProducerIndex();
return UnsafeRefArrayAccess.lvElement(buffer, calcElementOffset(currentHead));
return lvElement(buffer, calcElementOffset(currentHead));
}

@Override
Expand Down

0 comments on commit 061fce0

Please sign in to comment.