atomic64_xchg(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… atomic64_xchg β€” Kernel API Manual πŸ’…

okay so bestie, you're reading atomic64_xchg(9) from the Kernel API Manual, and honestly? She's a classic. Let's get into it 🫢


✨ NAME ✨

atomic64_xchg β€” atomic exchange with full ordering 🌈


πŸ¦‹ SYNOPSIS πŸ¦‹

s64 atomic64_xchg (atomic64_t *v , s64 new );

🌸 ARGUMENTS 🌸

  • v β€” pointer to atomic64_t πŸ’« (this is the thing you're swapping into)
  • new β€” the s64 value to assign πŸŽ€

πŸ’– DESCRIPTION πŸ’–

She atomically updates v to new, and does it with full ordering ✨. Like, the whole thing is one unit of swappy-swap, no cap. No half-states, no "oops I saw the middle", just boom β€” done 🧚

⚠️ okay so this is the important part: it's unsafe to use in noinstr code πŸ’€. If you're in noinstr land, you use raw_atomic64_xchg there instead. That's the rule, fr fr.

πŸŽ€ RETURN πŸŽ€

The original value of v β€” aka what was there before you came in and replaced it πŸ‘‘


🌈 SEE ALSO 🌈

Kernel file ./include/linux/atomic/atomic-instrumented.h πŸ’œ

And now, the friend group 🫢 β€” the whole 32-bit atomic_* gang:

The 64-bit girlies (atomic64_* β€” this is our house 🏠, bestie):

And the atomic_long_* cousins slaying on the side πŸ‘‘:


🌸 that's the whole page, bestie β€” go swap something atomically and stay ordered out there πŸ’…βœ¨

./include/linux/atomic β€” October 2026 πŸŽ€ that's where this queen lives and when she was last seen, mwah πŸ’‹

πŸ“¦ where this page comes from