QB_ATOMIC_...D_EXCHANGE(3)

πŸ’– QB_ATOMIC_...D_EXCHANGE(3) πŸ’–

okay bestie, so this one lives in the libqb Programmer's Manual and honestly? it's giving "tiny function, enormous power." her whole name is qb_atomic_int_compare_and_exchange and she's about to become your new hyperfixation. no cap. πŸ¦‹


✨ NAME ✨

qb_atomic_int_compare_and_exchange β€” compares oldval with the integer pointed to by atomic and, if they're equal, atomically exchanges *atomic with newval. πŸ’…

like... she checks if you're the same person, and if you are, she swaps you out. iconic behaviour honestly.


🌸 SYNOPSIS 🌸

#include <qb/qbatomic.h>

int32_t qb_atomic_int_compare_and_exchange(
    volatile int32_t QB_GNUC_MAY_ALIAS   *atomic,  /* a pointer to an integer */
    int32_t                               oldval,  /* the assumed old value of *atomic */
    int32_t                               newval   /* the new value of *atomic*/
);

πŸŽ€ PARAMS πŸŽ€

  • atomic β€” a pointer to an integer. she's the one getting compared and possibly swapped. main character energy fr fr. πŸ‘‘
  • oldval β€” the assumed old value of *atomic. you're basically guessing "i think she's currently this." 🫢
  • newval β€” the new value of *atomic. the glow-up you're giving her if the vibe check passes. ✨

πŸ’€ DESCRIPTION πŸ’€

Also acts as a memory barrier.

that's it, that's the description, but bestie do not sleep on that sentence β€” it's the whole point. she's not just comparing numbers, she's putting a whole fence in the memory ordering. it's giving bouncer at the club. 🚧


⭐ RETURN VALUE ⭐

  • QB_TRUE β€” if *atomic was equal oldval. she said yes. slay. πŸŽ‰
  • QB_FALSE β€” otherwise. she said no. not me getting rejected by an atomic operation 😭

πŸ”₯ SEE ALSO πŸ”₯

the whole friend group, because she does not work alone:

go read them. iykyk. 🌈


Copyright (C) 2003 Sebastian Wilhelmi

that's the whole page, bestie, and yes i know the title looks like it got cut off mid-sentence β€” it's literally QB_ATOMIC_...D_EXCHANGE(3), from libqb, dated 2025-09-16, and the footer says LIBQB too. mwah. πŸ’–

πŸ“¦ where this page comes from