raw_atomic_long_try_cmpxchg(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… raw_atomic_long_try_cmpxchg (9) πŸ’…

okay so you found the page bestie β€” this is from the Kernel API Manual and it's literally the "compare and swap, but make it raw" girlie. full ordering, no notes, let's go 🫢


✨ SYNOPSIS ✨

bool raw_atomic_long_try_cmpxchg (atomic_long_t *v , long *old , long new );

look at her. three args, one bool, zero drama πŸ’–


πŸŽ€ ARGUMENTS πŸŽ€

  • v β€” pointer to atomic_long_t. the thing we're plotting against πŸ‘€
  • old β€” pointer to the long value you wanna compare with. note: pointer, not the value itself. yes, really, it's a whole thing πŸ’€
  • new β€” the long value to assign. the glow-up you're trying to give v ✨

🌸 DESCRIPTION 🌸

so here's the tea β˜• if (v == old), she atomically updates v to new with full ordering. slay, iconic, no cap πŸ”₯

but if that comparison does not hold? then nope β€” v is not modified at all. instead, old gets updated to the current value of v, and relaxed ordering is provided. it's giving "the boomerang of information" πŸͺƒ iykyk

✨ wild but true: this one is safe to use in noinstr code. but the page says to prefer atomic_long_try_cmpxchg everywhere else β€” so she's the specialist, not the default πŸ’…

πŸ¦‹ RETURN πŸ¦‹

true if the exchange actually occurred, false otherwise. binary queen πŸ‘‘


🌈 SEE ALSO 🌈

the whole friend group fr fr β€” she's not doing this alone:

reading & setting

adding

subtracting

incrementing

decrementing

bitwise and / andnot

bitwise or / xor

exchanging

the cmpxchg cousins (our girl's whole bloodline πŸ’œ)

tests & negativity

the "unless" girlies (conditional queens) πŸ‘‘

the source β€” Kernel file ./include/linux/atomic/atomic-long.h πŸ“


and that's the whole page bestie, no crumbs left πŸ“ she lives in ./include/linux/atomic, she's stamped October 2026, and she's out here representing the Kernel API Manual with main character energy. periodt. πŸ’…βœ¨

πŸ“¦ where this page comes from