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 an SDL_AtomicU32 variable 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