Atomic Types
This page documents the atomic integer types exposed to AngelScript. Use these for thread-safe counters, flags, and shared state across callbacks/threads without needing a mutex for simple operations.
Overview
Two value types are available:
atomic_int32— 32-bit signed atomic integeratomic_int64— 64-bit signed atomic integer
These types provide common atomic operations such as load/store, exchange, compare-and-swap, arithmetic, and bitwise ops.
atomic_int32
atomic_int32Constructors
atomic_int32()
Creates an atomic value initialized to 0.
atomic_int32(int32 v)
Creates an atomic value initialized to v.
atomic_int32(const atomic_int32 &in other)
Copy-constructs from another atomic.
Assignment
atomic_int32 &opAssign(const atomic_int32 &in other)
atomic_int32&
Assigns the value from another atomic.
Methods
int32 load() const
int32
Atomically reads the current value.
void store(int32 v)
void
Atomically stores v.
int32 exchange(int32 v)
int32
Atomically sets to v and returns the previous value.
bool compare_exchange(int32 expected, int32 desired)
bool
Atomically sets to desired only if current value equals expected. Returns true on success.
int32 add(int32 v)
int32
Atomically adds v. Returns the previous value.
int32 sub(int32 v)
int32
Atomically subtracts v. Returns the previous value.
int32 and_op(int32 v)
int32
Atomically ANDs with v. Returns the previous value.
int32 or_op(int32 v)
int32
Atomically ORs with v. Returns the previous value.
int32 xor_op(int32 v)
int32
Atomically XORs with v. Returns the previous value.
int32 increment()
int32
Atomically increments by 1. Returns the new value.
int32 decrement()
int32
Atomically decrements by 1. Returns the new value.
atomic_int64
atomic_int64Constructors
atomic_int64()
Creates an atomic value initialized to 0.
atomic_int64(int64 v)
Creates an atomic value initialized to v.
atomic_int64(const atomic_int64 &in other)
Copy-constructs from another atomic.
Assignment
atomic_int64 &opAssign(const atomic_int64 &in other)
atomic_int64&
Assigns the value from another atomic.
Methods
int64 load() const
int64
Atomically reads the current value.
void store(int64 v)
void
Atomically stores v.
int64 exchange(int64 v)
int64
Atomically sets to v and returns the previous value.
bool compare_exchange(int64 expected, int64 desired)
bool
Atomically sets to desired only if current value equals expected. Returns true on success.
int64 add(int64 v)
int64
Atomically adds v. Returns the previous value.
int64 sub(int64 v)
int64
Atomically subtracts v. Returns the previous value.
int64 and_op(int64 v)
int64
Atomically ANDs with v. Returns the previous value.
int64 or_op(int64 v)
int64
Atomically ORs with v. Returns the previous value.
int64 xor_op(int64 v)
int64
Atomically XORs with v. Returns the previous value.
int64 increment()
int64
Atomically increments by 1. Returns the new value.
int64 decrement()
int64
Atomically decrements by 1. Returns the new value.
Return Value Notes (Important)
Some methods return the old value, while others return the new value:
Returns previous value:
exchange,add,sub,and_op,or_op,xor_opReturns new value:
increment,decrementReturns bool:
compare_exchange(success/failure)
Example Usage (Test Script)
Last updated