atomic_long_cmpxchg(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

✨ atomic_long_cmpxchg(9) ✨

okay so real quick β€” this page is straight out of the Kernel API Manual, section 9, and the star of the show is atomic_long_cmpxchg. bestie, it's a compare-and-swap and it's lowkey iconic πŸ’…


πŸŽ€ NAME πŸŽ€

atomic_long_cmpxchg β€” atomic compare and exchange with full ordering

like, it compares, it exchanges, and it does the ordering thing fully. no cap ✨


πŸ¦‹ SYNOPSIS πŸ¦‹

long atomic_long_cmpxchg (atomic_long_t *v , long old , long new );

🌸 ARGUMENTS 🌸

  • v β€” pointer to atomic_long_t. it's giving "the thing we're messing with" 🫢
  • old β€” the long value to compare with. the vibe check value, basically 🌈
  • new β€” the long value to assign. what we swap in if the vibe check passes πŸ’–

πŸ’œ DESCRIPTION πŸ’œ

okay so picture this: if (v == old), it atomically updates v to new, and it does that with full ordering. slay.

otherwise, v is not modified and relaxed ordering is provided. so like, nothing happens to your value, and the ordering gets downgraded. not me being chill about it πŸ™ˆ

⚠️ Unsafe to use in noinstr code β€” use raw_atomic_long_cmpxchg there instead. fr fr, don't do it, that's the whole warning πŸ’€

⭐ RETURN ⭐

the original value of v. that's it, that's the return. it's giving receipts πŸ‘‘


πŸ‘‘ SEE ALSO πŸ‘‘

first up, the kernel file this all lives in: ./include/linux/atomic/atomic-instrumented.h 🧚

πŸ’« the atomic_* crew

πŸ¦‹ the atomic64_* crew

πŸ’– the atomic_long_* crew (our homegirls)


and that's the whole page, bestie 🫢 this cutie lives in ./include/linux/atomic, dated October 2026 β€” go read it, periodt πŸ’…βœ¨

πŸ“¦ where this page comes from