raw_atomic64_cmpxchg(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… raw_atomic64_cmpxchg(9) β€” from the Kernel API Manual, bestie

okay so picture this: you're deep in the kernel, it's late, and you need a compare-and-swap that goes all the way on the ordering. that's this. welcome to raw_atomic64_cmpxchg(9), the full-ordering baddie of the raw atomic64 family. she's iconic, she's precise, and she has main character energy. πŸŽ€


✨ SYNOPSIS ✨

s64 raw_atomic64_cmpxchg (atomic64_t *v , s64 old , s64 new );

like, that's the whole vibe. three args, one s64 coming back at you. no cap. πŸ¦‹


🌸 ARGUMENTS 🌸

  • v β€” pointer to atomic64_t. this is the thing we're lookin' at, bestie. the target. the moment. πŸ‘‘
  • old β€” an s64 value to compare with. like, "is v giving old today or not" energy. πŸ”
  • new β€” an s64 value to assign. this is what v gets to become if the vibe check passes. ✨

πŸ’– DESCRIPTION πŸ’–

okay so here's the tea: if (v == old), it atomically updates v to new with full ordering. like, full. ordering. no shortcuts, no relaxed nonsense, the whole memory-barrier moment. periodt. πŸ”₯

otherwise β€” and this is the part people miss β€” v is not modified, and relaxed ordering is provided. so if the compare doesn't hit, you get the chill version. not me having two different orderings in one function 😭

and here's the bonus: it's safe to use in noinstr code. that's literally the whole point of the raw_ prefix, iykyk. but outside of that? please, prefer atomic64_cmpxchg elsewhere. that's not a suggestion, that's the manual telling you directly. 🫢


⭐ RETURN ⭐

the original value of v. that's it, that's the return. 🎁

so yeah, you always find out what was actually in there β€” whether your compare landed or not β€” because the function hands you the pre-swap value either way. slay. πŸ’œ


πŸ¦‹ SEE ALSO πŸ¦‹

the whole squad, fr fr. every single one of these is (9):

not me listing every single relative and then some πŸ’€ but that's the family, bestie β€” read them, love them, know them. 🌈

and the kernel file that's living rent-free behind all of this: ./include/linux/atomic/atomic-arch-fallback.h 🐧


okay that's the page!! mwah πŸ’‹ this lil slice of lore comes to you from ./include/linux/atomic, dated October 2026 β€” so yeah, she's from the future and she's still serving full ordering. go forth and compare-and-exchange responsibly, bestie πŸ«ΆπŸŽ€πŸ’–

πŸ“¦ where this page comes from