edu.mines.jtk.util
Class AtomicFloat

java.lang.Object
  extended by java.lang.Number
      extended by edu.mines.jtk.util.AtomicFloat
All Implemented Interfaces:
java.io.Serializable

public class AtomicFloat
extends java.lang.Number
implements java.io.Serializable

A float value that may be updated atomically. An atomic float works like an atomic integer. (See AtomicInteger.) For example, an atomic float might be used for parallel computation of the dot product of two vectors of floats.

Version:
2007.07.27
Author:
Dave Hale, Colorado School of Mines
See Also:
Serialized Form

Constructor Summary
AtomicFloat()
          Constructs an atomic float with initial value zero.
AtomicFloat(float value)
          Constructs an atomic float with specified initial value.
 
Method Summary
 float addAndGet(float delta)
          Atomically adds a specified value to the value of this float.
 boolean compareAndSet(float expect, float update)
          Atomically sets this float to the specified updated value if the current value equals the specified expected value.
 float decrementAndGet()
          Atomically decrements by one the value of this float.
 double doubleValue()
           
 float floatValue()
           
 float get()
          Gets the current value of this float.
 float getAndAdd(float delta)
          Atomically adds a specified value to the value of this float.
 float getAndDecrement()
          Atomically decrements by one the value of this float.
 float getAndIncrement()
          Atomically increments by one the value of this float.
 float getAndSet(float value)
          Atomically sets the value of this float and returns its old value.
 float incrementAndGet()
          Atomically increments by one the value of this float.
 int intValue()
           
 long longValue()
           
 void set(float value)
          Sets the value of this float.
 java.lang.String toString()
           
 boolean weakCompareAndSet(float expect, float update)
          Atomically sets this float to the specified updated value if the current value equals the specified expected value.
 
Methods inherited from class java.lang.Number
byteValue, shortValue
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

AtomicFloat

public AtomicFloat()
Constructs an atomic float with initial value zero.


AtomicFloat

public AtomicFloat(float value)
Constructs an atomic float with specified initial value.

Parameters:
value - the initial value.
Method Detail

get

public final float get()
Gets the current value of this float.

Returns:
the current value.

set

public final void set(float value)
Sets the value of this float.

Parameters:
value - the new value.

getAndSet

public final float getAndSet(float value)
Atomically sets the value of this float and returns its old value.

Parameters:
value - the new value.
Returns:
the old value.

compareAndSet

public final boolean compareAndSet(float expect,
                                   float update)
Atomically sets this float to the specified updated value if the current value equals the specified expected value.

Parameters:
expect - the expected value.
update - the updated value.
Returns:
true, if successfully set; false, if the current value was not equal to the expected value.

weakCompareAndSet

public final boolean weakCompareAndSet(float expect,
                                       float update)
Atomically sets this float to the specified updated value if the current value equals the specified expected value.

My fail spuriously, and does not provide ordering guarantees, so is only rarely useful.

Parameters:
expect - the expected value.
update - the updated value.
Returns:
true, if successfully set; false, if the current value was not equal to the expected value.

getAndIncrement

public final float getAndIncrement()
Atomically increments by one the value of this float.

Returns:
the previous value of this float.

getAndDecrement

public final float getAndDecrement()
Atomically decrements by one the value of this float.

Returns:
the previous value of this float.

getAndAdd

public final float getAndAdd(float delta)
Atomically adds a specified value to the value of this float.

Parameters:
delta - the value to add.
Returns:
the previous value of this float.

incrementAndGet

public final float incrementAndGet()
Atomically increments by one the value of this float.

Returns:
the updated value of this float.

decrementAndGet

public final float decrementAndGet()
Atomically decrements by one the value of this float.

Returns:
the updated value of this float.

addAndGet

public final float addAndGet(float delta)
Atomically adds a specified value to the value of this float.

Parameters:
delta - the value to add.
Returns:
the updated value of this float.

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

intValue

public int intValue()
Specified by:
intValue in class java.lang.Number

longValue

public long longValue()
Specified by:
longValue in class java.lang.Number

floatValue

public float floatValue()
Specified by:
floatValue in class java.lang.Number

doubleValue

public double doubleValue()
Specified by:
doubleValue in class java.lang.Number