atomic topic

CategoryAtomic

Atomic operations.

IMPORTANT: If you are not an expert in concurrent lockless programming, you should not be using any functions in this file. You should be protecting your data structures with full mutexes instead.

Seriously, here be dragons!

You can find out a little more about lockless programming and the subtle issues that can arise here: https://learn.microsoft.com/en-us/windows/win32/dxtecharts/lockless-programming

There's also lots of good information here:

These operations may or may not actually be implemented using processor specific atomic operations. When possible they are implemented as true processor specific atomic operations. When that is not possible the are implemented using locks that do use the available atomic operations.

All of the atomic operations that modify memory are full memory barriers.

Functions

sdlAddAtomicInt(Pointer<SdlAtomicInt> a, int v) int atomic
Add to an atomic variable.
sdlAddAtomicU32(Pointer<SdlAtomicU32> a, int v) int atomic
Add to an atomic variable.
sdlCompareAndSwapAtomicInt(Pointer<SdlAtomicInt> a, int oldval, int newval) bool atomic
Set an atomic variable to a new value if it is currently an old value.
sdlCompareAndSwapAtomicPointer(Pointer<Pointer<NativeType>> a, Pointer<NativeType> oldval, Pointer<NativeType> newval) bool atomic
Set a pointer to a new value if it is currently an old value.
sdlCompareAndSwapAtomicU32(Pointer<SdlAtomicU32> a, int oldval, int newval) bool atomic
Set an atomic variable to a new value if it is currently an old value.
sdlGetAtomicInt(Pointer<SdlAtomicInt> a) int atomic
Get the value of an atomic variable.
sdlGetAtomicPointer(Pointer<Pointer<NativeType>> a) Pointer<NativeType> atomic
Get the value of a pointer atomically.
sdlGetAtomicU32(Pointer<SdlAtomicU32> a) int atomic
Get the value of an atomic variable.
sdlLockSpinlock(Pointer<Int32> lock) → void atomic
Lock a spin lock by setting it to a non-zero value.
sdlMemoryBarrierAcquireFunction() → void atomic
Insert a memory acquire barrier (function version).
sdlMemoryBarrierReleaseFunction() → void atomic
Insert a memory release barrier (function version).
sdlSetAtomicInt(Pointer<SdlAtomicInt> a, int v) int atomic
Set an atomic variable to a value.
sdlSetAtomicPointer(Pointer<Pointer<NativeType>> a, Pointer<NativeType> v) Pointer<NativeType> atomic
Set a pointer to a value atomically.
sdlSetAtomicU32(Pointer<SdlAtomicU32> a, int v) int atomic
Set an atomic variable to a value.
sdlTryLockSpinlock(Pointer<Int32> lock) bool atomic
Try to lock a spin lock by setting it to a non-zero value.
sdlUnlockSpinlock(Pointer<Int32> lock) → void atomic
Unlock a spin lock by setting it to 0.