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 a void*. 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_TRUE if atomic was equal to oldval β€” you guessed right, she swapped, slay πŸŽ‰
  • QB_FALSE otherwise β€” nope, the value wasn't what you thought, nothing happened, no harm done 🫠

πŸ‘‘ SEE ALSO πŸ‘‘

the whole friend group, they're all connected, iykyk:


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