SDL3pp
A slim C++ wrapper for SDL3
Loading...
Searching...
No Matches
Public Member Functions | List of all members
SDL::AtomicU32 Struct Reference

A type representing an atomic unsigned 32-bit value. More...

Inheritance diagram for SDL::AtomicU32:
Inheritance graph
[legend]
Collaboration diagram for SDL::AtomicU32:
Collaboration graph
[legend]

Public Member Functions

constexpr AtomicU32 (Uint32 value)
 Wraps value. More...
 
 AtomicU32 (const AtomicU32 &value)=delete
 
AtomicU32operator= (const AtomicU32 &value)=delete
 
bool CompareAndSwap (Uint32 oldval, Uint32 newval)
 Set an atomic variable to a new value if it is currently an old value. More...
 
Uint32 Set (Uint32 v)
 Set an atomic variable to a value. More...
 
Uint32 Get ()
 Get the value of an atomic variable. More...
 

Detailed Description

This can be used to manage a value that is synchronized across multiple CPUs without a race condition; when an app sets a value with AtomicU32.Set all other threads, regardless of the CPU it is running on, will see that value when retrieved with AtomicU32.Get, regardless of CPU caches, etc.

This is also useful for atomic compare-and-swap operations: a thread can change the value as long as its current value matches expectations. When done in a loop, one can guarantee data consistency across threads without a lock (but the usual warnings apply: if you don't know what you're doing, or you don't do it carefully, you can confidently cause any number of disasters with this, so in most cases, you should use a mutex instead of this!).

This is a struct so people don't accidentally use numeric operations on it directly. You have to use SDL atomic functions.

Since
This struct is available since SDL 3.2.0.
See also
AtomicU32.CompareAndSwap
AtomicU32.Get
AtomicU32.Set

Constructor & Destructor Documentation

◆ AtomicU32()

constexpr SDL::AtomicU32::AtomicU32 ( Uint32  value)
inlineconstexpr
Parameters
valuethe value to be wrapped

The documentation for this struct was generated from the following file: