Package dev.gmitch215.bytebox.locks
Class AtomicIntegerArray
java.lang.Object
dev.gmitch215.bytebox.locks.AtomicIntegerArray
java.util.concurrent.atomic.AtomicIntegerArray, which the class library does not carry even
though it carries AtomicInteger.
Indivisible for the same reason as AtomicReferenceArray: one fiber runs at a time and
none of these operations suspends, so no two of them interleave.
- Since:
- 1.0.2
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal intaddAndGet(int i, int delta) final booleancompareAndSet(int i, int expect, int update) final intdecrementAndGet(int i) final intget(int i) final intgetAndAdd(int i, int delta) final intgetAndDecrement(int i) final intgetAndIncrement(int i) final intgetAndSet(int i, int newValue) final intincrementAndGet(int i) final voidlazySet(int i, int newValue) final intlength()Returns how many elements.final voidset(int i, int newValue) toString()final booleanweakCompareAndSet(int i, int expect, int update)
-
Constructor Details
-
AtomicIntegerArray
public AtomicIntegerArray(int length) - Parameters:
length- how many elements, each starting zero
-
AtomicIntegerArray
public AtomicIntegerArray(int[] array) - Parameters:
array- the elements to copy
-
-
Method Details
-
length
public final int length()Returns how many elements.- Returns:
- how many elements
-
get
public final int get(int i) - Parameters:
i- the index- Returns:
- the element
-
set
public final void set(int i, int newValue) - Parameters:
i- the indexnewValue- the value to store
-
lazySet
public final void lazySet(int i, int newValue) - Parameters:
i- the indexnewValue- the value to store
-
getAndSet
public final int getAndSet(int i, int newValue) - Parameters:
i- the indexnewValue- the value to store- Returns:
- the value that was there
-
compareAndSet
public final boolean compareAndSet(int i, int expect, int update) - Parameters:
i- the indexexpect- the value that must be thereupdate- the value to store- Returns:
- whether it was stored
-
weakCompareAndSet
public final boolean weakCompareAndSet(int i, int expect, int update) - Parameters:
i- the indexexpect- the value that must be thereupdate- the value to store- Returns:
- whether it was stored
-
getAndAdd
public final int getAndAdd(int i, int delta) - Parameters:
i- the indexdelta- how much to add- Returns:
- the value before adding
-
addAndGet
public final int addAndGet(int i, int delta) - Parameters:
i- the indexdelta- how much to add- Returns:
- the value after adding
-
getAndIncrement
public final int getAndIncrement(int i) - Parameters:
i- the index- Returns:
- the value before incrementing
-
getAndDecrement
public final int getAndDecrement(int i) - Parameters:
i- the index- Returns:
- the value before decrementing
-
incrementAndGet
public final int incrementAndGet(int i) - Parameters:
i- the index- Returns:
- the value after incrementing
-
decrementAndGet
public final int decrementAndGet(int i) - Parameters:
i- the index- Returns:
- the value after decrementing
-
toString
-