type

AtomicInt

src @Js
const class AtomicInt : Obj

AtomicInt is used to manage an integer variable shared between actor/threads with atomic updates.

constructors

make

Construct with initial value

fields

val

The current integer value

methods

add

Atomically add the given value to the current value

addAndGet

Atomically add the given value to the current value and return the updated value.

compareAndSet

Atomically set the value to update if current value is equivalent to the expect value.

decrement

Atomically decrement the value by one

decrementAndGet

Atomically decrement the current value by one and return the updated value.

getAndAdd

Atomically add the given value to the current value and return the previous value.

getAndDecrement

Atomically decrement the current value by one and return the previous value.

getAndIncrement

Atomically increment the current value by one and return the previous value.

getAndSet

Atomically set the value and return the previous value.

increment

Atomically increment the value by one

incrementAndGet

Atomically increment the current value by one and return the updated value.

toStr

Return val.toStr

Slot Details

add

src Void add(Int delta)

Atomically add the given value to the current value

addAndGet

src Int addAndGet(Int delta)

Atomically add the given value to the current value and return the updated value.

compareAndSet

src Bool compareAndSet(Int expect, Int update)

Atomically set the value to update if current value is equivalent to the expect value. Return true if updated, or false if current value was not equal to the expected value.

decrement

src Void decrement()

Atomically decrement the value by one

decrementAndGet

src Int decrementAndGet()

Atomically decrement the current value by one and return the updated value.

getAndAdd

src Int getAndAdd(Int delta)

Atomically add the given value to the current value and return the previous value.

getAndDecrement

src Int getAndDecrement()

Atomically decrement the current value by one and return the previous value.

getAndIncrement

src Int getAndIncrement()

Atomically increment the current value by one and return the previous value.

getAndSet

src Int getAndSet(Int val)

Atomically set the value and return the previous value.

increment

src Void increment()

Atomically increment the value by one

incrementAndGet

src Int incrementAndGet()

Atomically increment the current value by one and return the updated value.

make

src new make(Int val := 0)

Construct with initial value

toStr

src virtual override Str toStr()

Return val.toStr

val

src Int val

The current integer value