SDL_AddAtomicInt(3)

πŸ’– SDL_AddAtomicInt πŸ’–

okay bestie, so this one is from the SDL3 manual (that's the SDL3 FUNCTIONS crew, iykyk) and it's called SDL_AddAtomicInt β€” and yes, it does exactly what it says on the tin: it adds to an atomic variable. slay.


✨ NAME ✨

SDL_AddAtomicInt β€” add to an atomic variable. that's it, that's the whole vibe. πŸŽ€


🌸 SYNOPSIS 🌸

#include <SDL3/SDL_atomic.h>

int SDL_AddAtomicInt(SDL_AtomicInt *a, int v);

look at her. gorgeous. two params, one int back. main character energy fr fr. πŸ‘‘


πŸ¦‹ DESCRIPTION πŸ¦‹

so like, this function adds to an atomic variable, right? but plot twist: it also acts as a full memory barrier. that's not a little side note, that's a whole extra job and she's doing it for free. πŸ’…

⚠️ Note: if you don't know what this function is for, you shouldn't use it! like... genuinely. this is not a "just try it and see" situation bestie. if you don't already know why you need it, you don't need it. step away from the atomics. 🫢

πŸŽ€ FUNCTION PARAMETERS πŸŽ€

  • a β€” a pointer to an SDL_AtomicInt variable that's getting modified. she's the one being changed. πŸ’–
  • v β€” the desired value to add. your contribution. your little gift. ✨

⭐ RETURN VALUE ⭐

returns the previous value of the atomic variable. not the new one β€” the before picture. so you get receipts of what it was, not what it became. 🌈


🧚 THREAD SAFETY 🧚

it is safe to call this function from any thread. any of them. all of them. go wild, no cap. πŸ”₯


πŸ’œ AVAILABILITY πŸ’œ

this function is available since SDL 3.2.0. if you're on anything older, sorry babe, she's not there yet. 😭


πŸ‘‘ SEE ALSO πŸ‘‘

the ref-counting girlies. go say hi. πŸ“


and that's the whole page bestie, no crumbs left. this iconic little number comes to you courtesy of Simple Directmedia Layer, sitting pretty at version SDL 3.4.18 β€” mwah, love that for her. now go add something atomically, safely, and with full memory-barrier energy. periodt. πŸ’…βœ¨πŸŒΈ

πŸ“¦ where this page comes from