Class AtomicBiInteger

All Implemented Interfaces:
Serializable

public class AtomicBiInteger extends AtomicLong
An AtomicLong with additional methods to treat it as two hi/lo integers.
See Also:
  • Constructor Details

    • AtomicBiInteger

      public AtomicBiInteger()
    • AtomicBiInteger

      public AtomicBiInteger(long encoded)
    • AtomicBiInteger

      public AtomicBiInteger(int hi, int lo)
  • Method Details

    • getHi

      public int getHi()
      Get the hi value.
      Returns:
      the hi value
    • getHi

      public static int getHi(long encoded)
      Gets a hi value from the given encoded value.
      Parameters:
      encoded - the encoded value
      Returns:
      the hi value
    • getLo

      public int getLo()
      Get the lo value.
      Returns:
      the lo value
    • getLo

      public static int getLo(long encoded)
      Gets a lo value from the given encoded value.
      Parameters:
      encoded - the encoded value
      Returns:
      the lo value
    • getAndSetHi

      public int getAndSetHi(int hi)
      Atomically sets the hi value without changing the lo value.
      Parameters:
      hi - the new hi value
      Returns:
      the previous hi value
    • getAndSetLo

      public int getAndSetLo(int lo)
      Atomically sets the lo value without changing the hi value.
      Parameters:
      lo - the new lo value
      Returns:
      the previous lo value
    • set

      public void set(int hi, int lo)
      Sets the hi and lo values.
      Parameters:
      hi - the new hi value
      lo - the new lo value
    • compareAndSetHi

      public boolean compareAndSetHi(int expectHi, int hi)

      Atomically sets the hi value to the given updated value only if the current value == the expected value.

      Concurrent changes to the lo value result in a retry.

      Parameters:
      expectHi - the expected hi value
      hi - the new hi value
      Returns:
      true if successful. False return indicates that the actual hi value was not equal to the expected hi value.
    • compareAndSetLo

      public boolean compareAndSetLo(int expectLo, int lo)

      Atomically sets the lo value to the given updated value only if the current value == the expected value.

      Concurrent changes to the hi value result in a retry.

      Parameters:
      expectLo - the expected lo value
      lo - the new lo value
      Returns:
      true if successful. False return indicates that the actual lo value was not equal to the expected lo value.
    • compareAndSet

      public boolean compareAndSet(long encoded, int hi, int lo)
      Atomically sets the values to the given updated values only if the current encoded value == the expected encoded value.
      Parameters:
      encoded - the expected encoded value
      hi - the new hi value
      lo - the new lo value
      Returns:
      true if successful. False return indicates that the actual encoded value was not equal to the expected encoded value.
    • compareAndSet

      public boolean compareAndSet(int expectHi, int hi, int expectLo, int lo)
      Atomically sets the hi and lo values to the given updated values only if the current hi and lo values == the expected hi and lo values.
      Parameters:
      expectHi - the expected hi value
      hi - the new hi value
      expectLo - the expected lo value
      lo - the new lo value
      Returns:
      true if successful. False return indicates that the actual hi and lo values were not equal to the expected hi and lo value.
    • addAndGetHi

      public int addAndGetHi(int delta)
      Atomically adds the given delta to the current hi value, returning the updated hi value.
      Parameters:
      delta - the delta to apply
      Returns:
      the updated hi value
    • addAndGetLo

      public int addAndGetLo(int delta)
      Atomically adds the given delta to the current lo value, returning the updated lo value.
      Parameters:
      delta - the delta to apply
      Returns:
      the updated lo value
    • add

      public void add(int deltaHi, int deltaLo)
      Atomically adds the given deltas to the current hi and lo values.
      Parameters:
      deltaHi - the delta to apply to the hi value
      deltaLo - the delta to apply to the lo value
    • toString

      public String toString()
      Overrides:
      toString in class AtomicLong
    • encode

      public static long encode(int hi, int lo)
      Encodes hi and lo values into a long.
      Parameters:
      hi - the hi value
      lo - the lo value
      Returns:
      the encoded value
    • encodeHi

      public static long encodeHi(long encoded, int hi)
      Sets the hi value into the given encoded value.
      Parameters:
      encoded - the encoded value
      hi - the hi value
      Returns:
      the new encoded value
    • encodeLo

      public static long encodeLo(long encoded, int lo)
      Sets the lo value into the given encoded value.
      Parameters:
      encoded - the encoded value
      lo - the lo value
      Returns:
      the new encoded value