Skip to content

Commit

Permalink
directly replace Fence with the methods setRelease, setVolatile, and …
Browse files Browse the repository at this point in the history
…getAcquire

Since we already have VALUE_FIELD, it is more semantically clear to directly replace Fence with the methods setRelease, setVolatile, and getAcquire. No need to set barriers via VarHandle
  • Loading branch information
chenggwang committed Sep 15, 2023
1 parent 15542cd commit 72522f8
Showing 1 changed file with 5 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,7 @@ public SequenceVarHandleBarrier()
*/
public SequenceVarHandleBarrier(final long initialValue)
{
VarHandle.releaseFence();
this.value = initialValue;
VALUE_FIELD.setRelease(this,initialValue);
}

/**
Expand All @@ -85,9 +84,7 @@ public SequenceVarHandleBarrier(final long initialValue)
*/
public long get()
{
long value = this.value;
VarHandle.acquireFence();
return value;
return (long) VALUE_FIELD.getAcquire(this);
}

/**
Expand All @@ -99,8 +96,7 @@ public long get()
*/
public void set(final long value)
{
VarHandle.releaseFence();
this.value = value;
VALUE_FIELD.setRelease(this,value);
}

/**
Expand All @@ -113,9 +109,7 @@ public void set(final long value)
*/
public void setVolatile(final long value)
{
VarHandle.releaseFence();
this.value = value;
VarHandle.fullFence();
VALUE_FIELD.setVolatile(this,value);
}

/**
Expand Down Expand Up @@ -156,4 +150,4 @@ public String toString()
{
return Long.toString(get());
}
}
}

0 comments on commit 72522f8

Please sign in to comment.