public class AtomicWord<T extends org.graalvm.word.WordBase> extends Object
word value that may be updated atomically. See the
java.util.concurrent.atomic package specification for description of the properties of
atomic variables.
Similar to AtomicReference, but for word types. A dedicated
implementation is necessary because Object and word types cannot be mixed.| Modifier and Type | Field and Description |
|---|---|
protected AtomicLong |
value
For simplicity, we convert the word value to a long and delegate to existing atomic
operations.
|
| Constructor and Description |
|---|
AtomicWord()
Creates a new AtomicWord with initial value
WordFactory.zero(). |
| Modifier and Type | Method and Description |
|---|---|
boolean |
compareAndSet(T expect,
T update)
Atomically sets the value to the given updated value if the current value
== the
expected value. |
T |
get()
Gets the current value.
|
T |
getAndSet(T newValue)
Atomically sets to the given value and returns the old value.
|
void |
set(T newValue)
Sets to the given value.
|
protected final AtomicLong value
public AtomicWord()
WordFactory.zero().public final T get()
public final void set(T newValue)
newValue - the new valuepublic final T getAndSet(T newValue)
newValue - the new valuepublic final boolean compareAndSet(T expect, T update)
== the
expected value.expect - the expected valueupdate - the new valuetrue if successful. False return indicates that the actual value was not
equal to the expected value.