QB_ATOMIC_...GE_AND_ADD(3)

πŸ’– NAME πŸ’–

qb_atomic_int_exchange_and_add β€” the girlies call it atomic add-and-tell-you-what-it-was-before, and she is adding val to the integer that atomic points at, all atomically, no cap ✨


🌸 SYNOPSIS 🌸

okay so first you gotta bring her in:

#include <qb/qbatomic.h>

and then she looks like this, bestie:

int32_t qb_atomic_int_exchange_and_add(
    volatile int32_t QB_GNUC_MAY_ALIAS   *atomic,  /* a pointer to an integer */
    int32_t                               val      /* the value to add to *atomic */
);

like. the way she takes a volatile int32_t pointer with that QB_GNUC_MAY_ALIAS garnish and hands you back an int32_t?? iconic behavior honestly πŸ’…


πŸŽ€ PARAMS πŸŽ€

  • atomic β€” a pointer to an integer 🫢 that's it, that's the whole vibe. she points at your int and she's ready.
  • val β€” the value to add to *atomic ✨ this is the lil number getting poured into the pot.

πŸ¦‹ DESCRIPTION πŸ¦‹

so here's the tea, bestie: she returns the value of *atomic just before the addition took place. not after. before. she's giving you the receipts of what it was, while quietly making it more. main character energy fr fr πŸ‘‘

also?? she acts as a memory barrier. yes ma'am, ordering respected, no sneaky reordering happening on her watch. periodt 🌈

ngl if you're doing lock-free stuff and you need the old value and the increment in one indivisible lil moment, this is your girl. iykyk πŸ’œ

⭐ RETURN VALUE ⭐

the value of *atomic before the addition. that's the whole gift. the pre-add snapshot. the before pic πŸ“ΈπŸ’–


πŸ”₯ SEE ALSO πŸ”₯

go read the whole friend group, they all slay in their own way 🧚✨


Copyright (C) 2003 Sebastian Wilhelmi πŸ’œ


and that's the page, bestie!! from the libqb Programmer's Manual (that's the manual name, we folded it in up top like a lil bow πŸŽ€), section 3, dated 2025-09-16, brought to you by LIBQB. mwah, go write something atomic, you ate πŸ’…πŸ’–

πŸ“¦ where this page comes from