raw_atomic64_xchg_acquire(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

🌸 raw_atomic64_xchg_acquire β€” Kernel API Manual, section 9, bestie πŸ’…

Okay so real talk: this page is raw_atomic64_xchg_acquire(9) from the Kernel API Manual, and it's honestly such a little icon. It's one function, it does one thing, and it does it atomically. No cap. Let's get into it ✨


✨ NAME ✨

raw_atomic64_xchg_acquire β€” atomic exchange, but make it acquire ordering πŸŽ€


πŸ¦‹ SYNOPSIS πŸ¦‹

s64 raw_atomic64_xchg_acquire (atomic64_t *v , s64 new );

πŸ‘‘ ARGUMENTS πŸ‘‘

  • v β€” pointer to atomic64_t. It's giving "the address of the thing we're about to swap out" 🫢
  • new β€” an s64 value to assign. This is the glow-up value going in πŸ’–

πŸ’œ DESCRIPTION πŸ’œ

So basically: it atomically updates v to new, with acquire ordering. Atomically means nobody can catch it mid-swap and see some cursed half-updated situation β€” it's all-or-nothing, periodt πŸ”₯

Also, and this is the part people always ask about: it's safe to use in noinstr code. But if you're not in noinstr code, the manpage itself says prefer atomic64_xchg_acquire elsewhere β€” so like, use the regular one unless you specifically need the raw one. iykyk πŸ’€


⭐ RETURN ⭐

It hands you back the original value of v β€” like, what was there before the swap. So you always know what got traded out, no mystery 🧚


🌈 SEE ALSO 🌈

First up, the kernel file it lives in β€” go say hi:

./include/linux/atomic/atomic-arch-fallback.h

And now the entire friend group. This is a long list, bestie, but everybody gets named πŸ’–

The 32-bit raw_atomic_ girlies (read/set/add/sub):

raw_atomic_read(9), raw_atomic_read_acquire(9), raw_atomic_set(9), raw_atomic_set_release(9), raw_atomic_add(9), raw_atomic_add_return(9), raw_atomic_add_return_acquire(9), raw_atomic_add_return_release(9), raw_atomic_add_return_relaxed(9), raw_atomic_fetch_add(9), raw_atomic_fetch_add_acquire(9), raw_atomic_fetch_add_release(9), raw_atomic_fetch_add_relaxed(9), raw_atomic_sub(9), raw_atomic_sub_return(9), raw_atomic_sub_return_acquire(9), raw_atomic_sub_return_release(9), raw_atomic_sub_return_relaxed(9), raw_atomic_fetch_sub(9), raw_atomic_fetch_sub_acquire(9), raw_atomic_fetch_sub_release(9), raw_atomic_fetch_sub_relaxed(9)

The inc/dec crew:

raw_atomic_inc(9), raw_atomic_inc_return(9), raw_atomic_inc_return_acquire(9), raw_atomic_inc_return_release(9), raw_atomic_inc_return_relaxed(9), raw_atomic_fetch_inc(9), raw_atomic_fetch_inc_acquire(9), raw_atomic_fetch_inc_release(9), raw_atomic_fetch_inc_relaxed(9), raw_atomic_dec(9), raw_atomic_dec_return(9), raw_atomic_dec_return_acquire(9), raw_atomic_dec_return_release(9), raw_atomic_dec_return_relaxed(9), raw_atomic_fetch_dec(9), raw_atomic_fetch_dec_acquire(9), raw_atomic_fetch_dec_release(9), raw_atomic_fetch_dec_relaxed(9)

The bitwise babes (and/andnot/or/xor):

raw_atomic_and(9), raw_atomic_fetch_and(9), raw_atomic_fetch_and_acquire(9), raw_atomic_fetch_and_release(9), raw_atomic_fetch_and_relaxed(9), raw_atomic_andnot(9), raw_atomic_fetch_andnot(9), raw_atomic_fetch_andnot_acquire(9), raw_atomic_fetch_andnot_release(9), raw_atomic_fetch_andnot_relaxed(9), raw_atomic_or(9), raw_atomic_fetch_or(9), raw_atomic_fetch_or_acquire(9), raw_atomic_fetch_or_release(9), raw_atomic_fetch_or_relaxed(9), raw_atomic_xor(9), raw_atomic_fetch_xor(9), raw_atomic_fetch_xor_acquire(9), raw_atomic_fetch_xor_release(9), raw_atomic_fetch_xor_relaxed(9)

The swap-and-compare squad:

raw_atomic_xchg(9), raw_atomic_xchg_acquire(9), raw_atomic_xchg_release(9), raw_atomic_xchg_relaxed(9), raw_atomic_cmpxchg(9), raw_atomic_cmpxchg_acquire(9), raw_atomic_cmpxchg_release(9), raw_atomic_cmpxchg_relaxed(9), raw_atomic_try_cmpxchg(9), raw_atomic_try_cmpxchg_acquire(9), raw_atomic_try_cmpxchg_release(9), raw_atomic_try_cmpxchg_relaxed(9)

The test-and-unless crew:

raw_atomic_sub_and_test(9), raw_atomic_dec_and_test(9), raw_atomic_inc_and_test(9), raw_atomic_add_negative(9), raw_atomic_add_negative_acquire(9), raw_atomic_add_negative_release(9), raw_atomic_add_negative_relaxed(9), raw_atomic_fetch_add_unless(9), raw_atomic_add_unless(9), raw_atomic_inc_not_zero(9), raw_atomic_inc_unless_negative(9), raw_atomic_dec_unless_positive(9), raw_atomic_dec_if_positive(9)


πŸ’« The 64-bit edition β€” the main character energy πŸ’«

read/set/add/sub, but 64:

raw_atomic64_read(9), raw_atomic64_read_acquire(9), raw_atomic64_set(9), raw_atomic64_set_release(9), raw_atomic64_add(9), raw_atomic64_add_return(9), raw_atomic64_add_return_acquire(9), raw_atomic64_add_return_release(9), raw_atomic64_add_return_relaxed(9), raw_atomic64_fetch_add(9), raw_atomic64_fetch_add_acquire(9), raw_atomic64_fetch_add_release(9), raw_atomic64_fetch_add_relaxed(9), raw_atomic64_sub(9), raw_atomic64_sub_return(9), raw_atomic64_sub_return_acquire(9), raw_atomic64_sub_return_release(9), raw_atomic64_sub_return_relaxed(9), raw_atomic64_fetch_sub(9), raw_atomic64_fetch_sub_acquire(9), raw_atomic64_fetch_sub_release(9), raw_atomic64_fetch_sub_relaxed(9)

inc/dec, the sequel:

raw_atomic64_inc(9), raw_atomic64_inc_return(9), raw_atomic64_inc_return_acquire(9), raw_atomic64_inc_return_release(9), raw_atomic64_inc_return_relaxed(9), raw_atomic64_fetch_inc(9), raw_atomic64_fetch_inc_acquire(9), raw_atomic64_fetch_inc_release(9), raw_atomic64_fetch_inc_relaxed(9), raw_atomic64_dec(9), raw_atomic64_dec_return(9), raw_atomic64_dec_return_acquire(9), raw_atomic64_dec_return_release(9), raw_atomic64_dec_return_relaxed(9), raw_atomic64_fetch_dec(9), raw_atomic64_fetch_dec_acquire(9), raw_atomic64_fetch_dec_release(9), raw_atomic64_fetch_dec_relaxed(9)

bitwise, but make it 64:

raw_atomic64_and(9), raw_atomic64_fetch_and(9), raw_atomic64_fetch_and_acquire(9), raw_atomic64_fetch_and_release(9), raw_atomic64_fetch_and_relaxed(9), raw_atomic64_andnot(9), raw_atomic64_fetch_andnot(9), raw_atomic64_fetch_andnot_acquire(9), raw_atomic64_fetch_andnot_release(9), raw_atomic64_fetch_andnot_relaxed(9), raw_atomic64_or(9), raw_atomic64_fetch_or(9), raw_atomic64_fetch_or_acquire(9), raw_atomic64_fetch_or_release(9), raw_atomic64_fetch_or_relaxed(9), raw_atomic64_xor(9), raw_atomic64_fetch_xor(9), raw_atomic64_fetch_xor_acquire(9), raw_atomic64_fetch_xor_release(9), raw_atomic64_fetch_xor_relaxed(9)

xchg / cmpxchg, the 64-bit remix:

raw_atomic64_xchg(9), raw_atomic64_xchg_release(9), raw_atomic64_xchg_relaxed(9), raw_atomic64_cmpxchg(9), raw_atomic64_cmpxchg_acquire(9), raw_atomic64_cmpxchg_release(9), raw_atomic64_cmpxchg_relaxed(9), raw_atomic64_try_cmpxchg(9), raw_atomic64_try_cmpxchg_acquire(9), raw_atomic64_try_cmpxchg_release(9), raw_atomic64_try_cmpxchg_relaxed(9)

test / unless, final form:

raw_atomic64_sub_and_test(9), raw_atomic64_dec_and_test(9), raw_atomic64_inc_and_test(9), raw_atomic64_add_negative(9), raw_atomic64_add_negative_acquire(9), raw_atomic64_add_negative_release(9), raw_atomic64_add_negative_relaxed(9), raw_atomic64_fetch_add_unless(9), raw_atomic64_add_unless(9), raw_atomic64_inc_not_zero(9), raw_atomic64_inc_unless_negative(9), raw_atomic64_dec_unless_positive(9), raw_atomic64_dec_if_positive(9)

Yes, every single one. I counted. You're welcome πŸ’…

πŸ“ the cute sign-off πŸ“

This absolute gem lives under ./include/linux/atomic and this version of the page is dated October 2026 β€” so like, it's from the future, iconic behavior honestly. Manual: Kernel API Manual, section 9, raw_atomic64_xchg_acquire(9).

Go swap something atomically bestie, and remember the acquire ordering. Mwah πŸ’–πŸŽ€πŸ¦‹

πŸ“¦ where this page comes from