java.util.concurrent.atomic
Class AtomicMarkableReference<V>

java.lang.Object sample code for java.lang.Object definition code for java.lang.Object 
  extended by java.util.concurrent.atomic.AtomicMarkableReference<V>
Type Parameters:
V - The type of object referred to by this reference

public class AtomicMarkableReference<V>
extends Object sample code for java.lang.Object definition code for java.lang.Object

An AtomicMarkableReference maintains an object reference along with a mark bit, that can be updated atomically.

Implementation note. This implementation maintains markable references by creating internal objects representing "boxed" [reference, boolean] pairs.

Since:
1.5

Constructor Summary
AtomicMarkableReference sample code for java.util.concurrent.atomic.AtomicMarkableReference.AtomicMarkableReference(V, boolean) definition code for java.util.concurrent.atomic.AtomicMarkableReference.AtomicMarkableReference(V, boolean) (V initialRef, boolean initialMark)
          Creates a new AtomicMarkableReference with the given initial values.
 
Method Summary
 boolean attemptMark sample code for java.util.concurrent.atomic.AtomicMarkableReference.attemptMark(V, boolean) definition code for java.util.concurrent.atomic.AtomicMarkableReference.attemptMark(V, boolean) (V expectedReference, boolean newMark)
          Atomically sets the value of the mark to the given update value if the current reference is == to the expected reference.
 boolean compareAndSet sample code for java.util.concurrent.atomic.AtomicMarkableReference.compareAndSet(V, V, boolean, boolean) definition code for java.util.concurrent.atomic.AtomicMarkableReference.compareAndSet(V, V, boolean, boolean) (V expectedReference, V newReference, boolean expectedMark, boolean newMark)
          Atomically sets the value of both the reference and mark to the given update values if the current reference is == to the expected reference and the current mark is equal to the expected mark.
 V get sample code for java.util.concurrent.atomic.AtomicMarkableReference.get(boolean[]) definition code for java.util.concurrent.atomic.AtomicMarkableReference.get(boolean[]) (boolean[] markHolder)
          Returns the current values of both the reference and the mark.
 V getReference sample code for java.util.concurrent.atomic.AtomicMarkableReference.getReference() definition code for java.util.concurrent.atomic.AtomicMarkableReference.getReference() ()
          Returns the current value of the reference.
 boolean isMarked sample code for java.util.concurrent.atomic.AtomicMarkableReference.isMarked() definition code for java.util.concurrent.atomic.AtomicMarkableReference.isMarked() ()
          Returns the current value of the mark.
 void set sample code for java.util.concurrent.atomic.AtomicMarkableReference.set(V, boolean) definition code for java.util.concurrent.atomic.AtomicMarkableReference.set(V, boolean) (V newReference, boolean newMark)
          Unconditionally sets the value of both the reference and mark.
 boolean weakCompareAndSet sample code for java.util.concurrent.atomic.AtomicMarkableReference.weakCompareAndSet(V, V, boolean, boolean) definition code for java.util.concurrent.atomic.AtomicMarkableReference.weakCompareAndSet(V, V, boolean, boolean) (V expectedReference, V newReference, boolean expectedMark, boolean newMark)
          Atomically sets the value of both the reference and mark to the given update values if the current reference is == to the expected reference and the current mark is equal to the expected mark.
 
Methods inherited from class java.lang.Object sample code for java.lang.Object definition code for java.lang.Object
clone sample code for java.lang.Object.clone() definition code for java.lang.Object.clone() , equals sample code for java.lang.Object.equals(java.lang.Object) definition code for java.lang.Object.equals(java.lang.Object) , finalize sample code for java.lang.Object.finalize() definition code for java.lang.Object.finalize() , getClass sample code for java.lang.Object.getClass() definition code for java.lang.Object.getClass() , hashCode sample code for java.lang.Object.hashCode() definition code for java.lang.Object.hashCode() , notify sample code for java.lang.Object.notify() definition code for java.lang.Object.notify() , notifyAll sample code for java.lang.Object.notifyAll() definition code for java.lang.Object.notifyAll() , toString sample code for java.lang.Object.toString() definition code for java.lang.Object.toString() , wait sample code for java.lang.Object.wait() definition code for java.lang.Object.wait() , wait sample code for java.lang.Object.wait(long) definition code for java.lang.Object.wait(long) , wait sample code for java.lang.Object.wait(long, int) definition code for java.lang.Object.wait(long, int)
 

Constructor Detail

AtomicMarkableReference sample code for java.util.concurrent.atomic.AtomicMarkableReference(V, boolean) definition code for java.util.concurrent.atomic.AtomicMarkableReference(V, boolean)

public AtomicMarkableReference(V initialRef,
                               boolean initialMark)
Creates a new AtomicMarkableReference with the given initial values.

Parameters:
initialRef - the initial reference
initialMark - the initial mark
Method Detail

getReference sample code for java.util.concurrent.atomic.AtomicMarkableReference.getReference() definition code for java.util.concurrent.atomic.AtomicMarkableReference.getReference()

public V getReference()
Returns the current value of the reference.

Returns:
the current value of the reference

isMarked sample code for java.util.concurrent.atomic.AtomicMarkableReference.isMarked() definition code for java.util.concurrent.atomic.AtomicMarkableReference.isMarked()

public boolean isMarked()
Returns the current value of the mark.

Returns:
the current value of the mark

get sample code for java.util.concurrent.atomic.AtomicMarkableReference.get(boolean[]) definition code for java.util.concurrent.atomic.AtomicMarkableReference.get(boolean[])

public V get(boolean[] markHolder)
Returns the current values of both the reference and the mark. Typical usage is boolean[1] holder; ref = v.get(holder); .

Parameters:
markHolder - an array of size of at least one. On return, markholder[0] will hold the value of the mark.
Returns:
the current value of the reference

weakCompareAndSet sample code for java.util.concurrent.atomic.AtomicMarkableReference.weakCompareAndSet(V, V, boolean, boolean) definition code for java.util.concurrent.atomic.AtomicMarkableReference.weakCompareAndSet(V, V, boolean, boolean)

public boolean weakCompareAndSet(V expectedReference,
                                 V newReference,
                                 boolean expectedMark,
                                 boolean newMark)
Atomically sets the value of both the reference and mark to the given update values if the current reference is == to the expected reference and the current mark is equal to the expected mark. Any given invocation of this operation may fail (return false) spuriously, but repeated invocation when the current value holds the expected value and no other thread is also attempting to set the value will eventually succeed.

Parameters:
expectedReference - the expected value of the reference
newReference - the new value for the reference
expectedMark - the expected value of the mark
newMark - the new value for the mark
Returns:
true if successful

compareAndSet sample code for java.util.concurrent.atomic.AtomicMarkableReference.compareAndSet(V, V, boolean, boolean) definition code for java.util.concurrent.atomic.AtomicMarkableReference.compareAndSet(V, V, boolean, boolean)

public boolean compareAndSet(V expectedReference,
                             V newReference,
                             boolean expectedMark,
                             boolean newMark)
Atomically sets the value of both the reference and mark to the given update values if the current reference is == to the expected reference and the current mark is equal to the expected mark.

Parameters:
expectedReference - the expected value of the reference
newReference - the new value for the reference
expectedMark - the expected value of the mark
newMark - the new value for the mark
Returns:
true if successful

set sample code for java.util.concurrent.atomic.AtomicMarkableReference.set(V, boolean) definition code for java.util.concurrent.atomic.AtomicMarkableReference.set(V, boolean)

public void set(V newReference,
                boolean newMark)
Unconditionally sets the value of both the reference and mark.

Parameters:
newReference - the new value for the reference
newMark - the new value for the mark

attemptMark sample code for java.util.concurrent.atomic.AtomicMarkableReference.attemptMark(V, boolean) definition code for java.util.concurrent.atomic.AtomicMarkableReference.attemptMark(V, boolean)

public boolean attemptMark(V expectedReference,
                           boolean newMark)
Atomically sets the value of the mark to the given update value if the current reference is == to the expected reference. Any given invocation of this operation may fail (return false) spuriously, but repeated invocation when the current value holds the expected value and no other thread is also attempting to set the value will eventually succeed.

Parameters:
expectedReference - the expected value of the reference
newMark - the new value for the mark
Returns:
true if successful