AtomicStampedReference
maintains an object reference
along with an integer "stamp", that can be updated atomically.Implementation Note
This implementation maintains stamped references by creating internal objects representing "boxed" [reference, integer] pairs.
Modifier and Type | Class and Description |
---|---|
private static class |
Modifier and Type | Field and Description |
---|---|
private volatile AtomicStampedReference. | |
private static final VarHandle |
Access | Constructor and Description |
---|---|
public | AtomicStampedReference(V
the initial reference initialRef, int the initial stamp initialStamp)Creates a new |
Modifier and Type | Method and Description |
---|---|
public boolean | Returns: true if successfulthe expected value of the reference expectedReference, int the new value for the stamp newStamp)Atomically sets the value of the stamp to the given update value
if the current reference is |
private boolean | |
public boolean | Returns: true if successfulthe expected value of the reference expectedReference, V the new value for the reference newReference, int the expected value of the stamp expectedStamp, int the new value for the stamp newStamp)Atomically sets the value of both the reference and stamp
to the given update values if the
current reference is |
public V | Returns: the current value of the referencean array of size of at least one. On return,
stampHolder)stampHolder[0] will hold the value of the stamp.Returns the current values of both the reference and the stamp. |
public V | Returns: the current value of the referenceReturns the current value of the reference. |
public int | |
public void | set(V
the new value for the reference newReference, int the new value for the stamp newStamp)Unconditionally sets the value of both the reference and stamp. |
public boolean | Returns: true if successfulthe expected value of the reference expectedReference, V the new value for the reference newReference, int the expected value of the stamp expectedStamp, int the new value for the stamp newStamp)Atomically sets the value of both the reference and stamp to
the given update values if the current reference is |
pair | back to summary |
---|---|
private volatile AtomicStampedReference. |
PAIR | back to summary |
---|---|
private static final VarHandle PAIR |
AtomicStampedReference | back to summary |
---|---|
public AtomicStampedReference(V initialRef, int initialStamp) Creates a new
|
attemptStamp | back to summary |
---|---|
public boolean attemptStamp(V expectedReference, int newStamp) Atomically sets the value of the stamp to the given update value
if the current reference is
|
casPair | back to summary |
---|---|
private boolean casPair(AtomicStampedReference. |
compareAndSet | back to summary |
---|---|
public boolean compareAndSet(V expectedReference, V newReference, int expectedStamp, int newStamp) Atomically sets the value of both the reference and stamp
to the given update values if the
current reference is
|
get | back to summary |
---|---|
public V get(int[] stampHolder) Returns the current values of both the reference and the stamp.
Typical usage is
|
getReference | back to summary |
---|---|
public V getReference() Returns the current value of the reference.
|
getStamp | back to summary |
---|---|
public int getStamp() Returns the current value of the stamp.
|
set | back to summary |
---|---|
public void set(V newReference, int newStamp) Unconditionally sets the value of both the reference and stamp.
|
weakCompareAndSet | back to summary |
---|---|
public boolean weakCompareAndSet(V expectedReference, V newReference, int expectedStamp, int newStamp) Atomically sets the value of both the reference and stamp to
the given update values if the current reference is
|
Modifier and Type | Field and Description |
---|---|
pack-priv final T | |
pack-priv final int |
Access | Constructor and Description |
---|---|
private |
Modifier and Type | Method and Description |
---|---|
pack-priv static <T> AtomicStampedReference. |
reference | back to summary |
---|---|
pack-priv final T reference |
stamp | back to summary |
---|---|
pack-priv final int stamp |
Pair | back to summary |
---|---|
private Pair(T reference, int stamp) |
of | back to summary |
---|---|
pack-priv static <T> AtomicStampedReference. |