Class AtomicBiInteger

  • All Implemented Interfaces:
    java.io.Serializable

    public class AtomicBiInteger
    extends java.util.concurrent.atomic.AtomicLong
    An AtomicLong with additional methods to treat it as two hi/lo integers.
    See Also:
    Serialized Form
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void add​(int deltaHi, int deltaLo)
      Atomically adds the given deltas to the current hi and lo values.
      int addAndGetHi​(int delta)
      Atomically adds the given delta to the current hi value, returning the updated hi value.
      int addAndGetLo​(int delta)
      Atomically adds the given delta to the current lo value, returning the updated lo value.
      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.
      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.
      boolean compareAndSetHi​(int expectHi, int hi)
      Atomically sets the hi value to the given updated value only if the current value == the expected value.
      boolean compareAndSetLo​(int expectLo, int lo)
      Atomically sets the lo value to the given updated value only if the current value == the expected value.
      static long encode​(int hi, int lo)
      Encodes hi and lo values into a long.
      static long encodeHi​(long encoded, int hi)
      Sets the hi value into the given encoded value.
      static long encodeLo​(long encoded, int lo)
      Sets the lo value into the given encoded value.
      int getAndSetHi​(int hi)
      Atomically sets the hi value without changing the lo value.
      int getAndSetLo​(int lo)
      Atomically sets the lo value without changing the hi value.
      int getHi()  
      static int getHi​(long encoded)
      Gets a hi value from the given encoded value.
      int getLo()  
      static int getLo​(long encoded)
      Gets a lo value from the given encoded value.
      void set​(int hi, int lo)
      Sets the hi and lo values.
      • Methods inherited from class java.util.concurrent.atomic.AtomicLong

        accumulateAndGet, addAndGet, compareAndExchange, compareAndExchangeAcquire, compareAndExchangeRelease, compareAndSet, decrementAndGet, doubleValue, floatValue, get, getAcquire, getAndAccumulate, getAndAdd, getAndDecrement, getAndIncrement, getAndSet, getAndUpdate, getOpaque, getPlain, incrementAndGet, intValue, lazySet, longValue, set, setOpaque, setPlain, setRelease, toString, updateAndGet, weakCompareAndSet, weakCompareAndSetAcquire, weakCompareAndSetPlain, weakCompareAndSetRelease, weakCompareAndSetVolatile
      • 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

      • AtomicBiInteger

        public AtomicBiInteger()
      • AtomicBiInteger

        public AtomicBiInteger​(long encoded)
      • AtomicBiInteger

        public AtomicBiInteger​(int hi,
                               int lo)
    • Method Detail

      • getHi

        public int getHi()
        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()
        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
      • 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