SDL_CompareAndSwapAtomicU32(3)
π SDL_CompareAndSwapAtomicU32 π
okay bestie, so this is a page from the SDL3 FUNCTIONS manual, and we're talking about SDL_CompareAndSwapAtomicU32 β the little compare-and-swap diva of the atomic world. π¦
β¨ NAME β¨
SDL_CompareAndSwapAtomicU32 β set an atomic variable to a new value if it is currently an old value.
like, the glow-up only happens if the vibe check passes first π
πΈ SYNOPSIS πΈ
#include <SDL3/SDL_atomic.h>
bool SDL_CompareAndSwapAtomicU32(SDL_AtomicU32 *a, Uint32 oldval, Uint32 newval);
π DESCRIPTION π
Note: If you don't know what this function is for, you shouldn't use it!
fr fr, that's not me being mean, that's literally in the manual π this is a low-level little creature and it does not play about correctness. if you're reading this like "hmm what does this even do tho" β step away from the keyboard, bestie, this one isn't for you yet. no cap.
π FUNCTION PARAMETERS π
aβ a pointer to anSDL_AtomicU32variable to be modified. this is the main character getting the makeover β¨oldvalβ the old value. the before pic πΈnewvalβ the new value. the after pic π
β RETURN VALUE β
Returns true if the atomic variable was set, false otherwise.
so basically: true = slay, we swapped it. false = nope, the value wasn't what you said it was, no swap happened, we move on π«Ά
π§ THREAD SAFETY π§
It is safe to call this function from any thread.
every thread can pull up, it's giving inclusive π no drama, no fighting over the variable, that's the whole point of an atomic iykyk
π AVAILABILITY π
This function is available since SDL 3.2.0. if your SDL is older than that, it's simply not gonna show up, and that's that π
π SEE ALSO π
the whole atomic squad, go read them too, they're all iconic π
Simple Directmedia Layer Β· SDL 3.4.18 β that's the source and the version, mwah, and that's the whole page bestie, thanks for reading, go write some thread-safe code and slay πβ¨π
π¦ where this page comes from
- fedora 43: SDL3-devel 3.4.18-1.fc43 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- fedora 43: SDL3-devel 3.4.18-1.fc43 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- fedora 44: SDL3-devel 3.4.18-1.fc44 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- fedora 44: SDL3-devel 3.4.18-1.fc44 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms