raw_atomic_xchg_acquire(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… raw_atomic_xchg_acquire β€” Kernel API Manual, bestie edition πŸŽ€

okay so you found the raw_atomic_xchg_acquire(9) page in the Kernel API Manual and you're like "what is this" β€” don't worry, I got you. This is a little one. A baby page. But she is important, so let's give her the main character energy she deserves ✨


🌸 NAME 🌸

raw_atomic_xchg_acquire β€” atomic exchange with acquire ordering πŸ’–

Like, you're swapping a value in and the ordering is acquire. Both things. At once. Iconic.


πŸ¦‹ SYNOPSIS πŸ¦‹

int raw_atomic_xchg_acquire (atomic_t *v , int new );

That's it. That's the whole vibe. Two arguments, one return, no cap πŸ’…


πŸ“ ARGUMENTS πŸ“

  • v β€” pointer to atomic_t. This is the thing you're swapping into, so like… know where it lives, bestie πŸ™ˆ
  • new β€” the int value to assign. The new one. The replacement. The glow-up ✨

πŸ”₯ DESCRIPTION πŸ”₯

Atomically updates v to new with acquire ordering. So the swap happens as one single atomic step β€” nobody can catch her mid-change β€” and the ordering on it is acquire 🫢

Safe to use in noinstr code; prefer atomic_xchg_acquire elsewhere. This is the important part, so let me say it cuter but with the exact same meaning: noinstr code? go off, use this one πŸ’– Everywhere else? atomic_xchg_acquire is your girl. It's giving "correct tool for the correct context" and I'm obsessed.


⭐ RETURN ⭐

The original value of v. Not the new one β€” the original one, the one that was there before you swapped her out πŸ‘‘ Like finding a note in a locker you just put your own note into. You get the old note back.


🌈 SEE ALSO 🌈

First up, the file this all lives in β€” kernel file ./include/linux/atomic/atomic-arch-fallback.h πŸ’€

Now, the family. And bestie, it is a big family. Every single one, no skipping, because they all matter and I refuse to do any of them dirty:

the 32-bit girlies β€” the basics

add era

sub era

inc era

dec era

bitwise: and / andnot

bitwise: or / xor

exchanges + compare-exchanges (our girl's siblings πŸ˜­πŸ’–)

test / negative / unless crew

and now the 64-bit girlies, because she has a whole second family 🌸

ngl that's a lot of cross-references and I typed every single one, so if you're still reading this far β€” you're the realest 🫢

🧚 and that's the whole page πŸ’œ

Little page, big energy. This one lives at ./include/linux/atomic (that's the source path, bestie), and this version is dated October 2026 ⭐ Go swap your values, respect the acquire ordering, and use atomic_xchg_acquire outside noinstr code β€” mwah πŸ’…πŸŽ€

πŸ“¦ where this page comes from