SDL_AtomicDecRef(3)

πŸ’– SDL_AtomicDecRef(3) πŸ’–

okay bestie, welcome to the SDL3 FUNCTIONS corner of the manual, where we talk about SDL_AtomicDecRef β€” the little macro that goes down so your refcount can go out. πŸ¦‹


✨ NAME ✨

SDL_AtomicDecRef β€” decrement an atomic variable used as a reference count. that's it, that's the whole job, and she does it flawlessly. πŸ’…


✨ SYNOPSIS ✨

#include <SDL3/SDL_atomic.h>

#define SDL_AtomicDecRef(a)    (SDL_AddAtomicInt(a, -1) == 1)

look at her. one line. no notes. πŸ”₯


✨ DESCRIPTION ✨

so basically this macro does a little minus one on your atomic reference count, atomically, so you don't have to stress about races. iconic behaviour, honestly. πŸ‘‘

Note: If you don't know what this macro is for, you shouldn't use it!

fr fr. this is not a "let me just try it and see" situation. if refcounting isn't already your whole personality, step away from the macro, bestie. πŸ™ˆ


✨ MACRO PARAMETERS ✨

  • a β€” a pointer to an SDL_AtomicInt to decrement. yes, a pointer, hand her the address, she'll handle the rest. 🫢

✨ RETURN VALUE ✨

Returns true if the variable reached zero after decrementing, false otherwise. so like β€” if it hit zero, that's your cue that you were the last one holding on and the cleanup is yours to do. main character moment. 🌸


✨ THREAD SAFETY ✨

It is safe to call this macro from any thread. any. thread. go wild, she's built different. 🌈


✨ AVAILABILITY ✨

This macro is available since SDL 3.2.0. so if you're on something older... bestie. 😭


✨ SEE ALSO ✨

  • SDL_AtomicIncRef(3) β€” the other half of the duo, the one who adds. they're a matching set, don't split them up. πŸ’œ

and that's the whole page, no cap. mwah. πŸ’‹

this has been a Simple Directmedia Layer production, brought to you by SDL 3.4.18 β€” ty for reading, ily, go fix your refcounts. πŸŽ€βœ¨

πŸ“¦ where this page comes from