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 π₯
qb_atomic_int_set(3)qb_atomic_int_compare_and_exchange(3)qb_atomic_int_get(3)qb_atomic_int_add(3)qb_atomic_init(3)qb_atomic_pointer_get(3)qb_atomic_pointer_compare_and_exchange(3)qb_atomic_pointer_set(3)
go read the whole friend group, they all slay in their own way π§β¨
π COPYRIGHT π
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
- fedora 44: libqb-devel 2.0.9-2.fc44 Β· LGPL-2.1-or-later
- fedora 44: libqb-devel 2.0.9-2.fc44 Β· LGPL-2.1-or-later
- ubuntu resolute: libqb-dev 2.0.9-1ubuntu1 Β· LGPL-2.1-or-later
- ubuntu stonking: libqb-dev 2.0.9-1ubuntu1 Β· LGPL-2.1-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms