QB_ATOMIC_...D_EXCHANGE(3)
π qb_atomic_pointer_compare_and_exchange β from the libqb Programmer's Manual β¨
okay bestie, sit down, hydrate, because we're talking about qb_atomic_pointer_compare_and_exchange, a function with a name so long it needs its own zip code π«Ά. This one lives in the libqb manual (section 3, the library-calls girlies) and she is literally the compare-and-swap of the pointer world. iconic behaviour, no cap π
πΈ NAME πΈ
qb_atomic_pointer_compare_and_exchange β she compares oldval with the pointer that atomic is pointing at, and if those two are equal, she atomically swaps *atomic with newval. that's it, that's the whole job, and she does it flawlessly π
β¨ SYNOPSIS β¨
#include <qb/qbatomic.h>
int32_t qb_atomic_pointer_compare_and_exchange(
volatile void *QB_GNUC_MAY_ALIAS *atomic, /* a pointer to a void* */
void *oldval, /* the assumed old value of *atomic */
void *newval /* the new value of *atomic*/
);
like look at her. the return type is int32_t, the vibes are immaculate π
π¦ PARAMS π¦
atomicβ a pointer to avoid*. that's the lil spot she's gonna peek at and maybe swap out πoldvalβ the assumed old value of*atomic. your guess at what's currently chillin' in there, bestie π€newvalβ the new value of*atomic. what you want it to become if the guess was right β¨
π DESCRIPTION π
she compares oldval against the pointer that atomic points to, and if they match? she swaps *atomic with newval atomically β all in one go, no interruptions, no half-finished nonsense, we do NOT do partial here π
Also acts as a memory barrier. yes ma'am. memory barrier. she's not just swapping, she's enforcing order in the universe. the way she does both at onceβ¦ main character energy fr fr π₯
β RETURN VALUE β
QB_TRUEifatomicwas equal tooldvalβ you guessed right, she swapped, slay πQB_FALSEotherwise β nope, the value wasn't what you thought, nothing happened, no harm done π«
π SEE ALSO π
the whole friend group, they're all connected, iykyk:
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_int_exchange_and_add(3)qb_atomic_pointer_set(3)
π COPYRIGHT π
Copyright (C) 2003 Sebastian Wilhelmi
that's the whole page bestie, go forth and atomically exchange responsibly π this diva came to you from LIBQB, dated 2025-09-16, and yes she's still serving QB_ATOMIC_...D_EXCHANGE(3) energy in the year of our lord twenty twenty-five. periodt π¦β¨
π¦ 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