raw_atomic_...xchg_relaxed(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

okay so bestie, welcome to the Kernel API Manual β€” this page’s header is raw_atomic_...xchg_relaxed(9), but the function that’s actually serving looks is raw_atomic_long_cmpxchg_relaxed. it’s giving atomic compare-and-swap with relaxed ordering, and I’m obsessed πŸ’…

πŸ’– NAME πŸ’–

raw_atomic_long_cmpxchg_relaxed β€” atomic compare and exchange with relaxed ordering. that’s the name, no notes. ✨

✨ SYNOPSIS ✨

here’s the signature, copy it exactly or the compiler will side-eye you:

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

πŸŽ€ ARGUMENTS πŸŽ€

  • v β€” pointer to atomic_long_t. literally a pointer to the atomic long you’re messing with. 🫢
  • old β€” long value to compare with. this is the β€œare you the one?” value. πŸ’…
  • new β€” long value to assign. the replacement if the vibe check passes. 🌸

πŸ¦‹ DESCRIPTION πŸ¦‹

okay so here’s the tea: if (v == old), it atomically updates v to new with relaxed ordering. otherwise, v is not modified and relaxed ordering is provided. literally that simple. πŸ¦‹

it’s safe to use in noinstr code; prefer atomic_long_cmpxchg_relaxed elsewhere. iykyk. πŸ‘‘

🌸 RETURN 🌸

the original value of v. that’s the whole return, bestie β€” no extra sparkle, just the value you had before. 🫢

πŸ‘‘ SEE ALSO πŸ‘‘

kernel file: ./include/linux/atomic/atomic-long.h

the whole extended friend group, every single one, no cap:

raw_atomic_long_read(9)
raw_atomic_long_read_acquire(9)
raw_atomic_long_set(9)
raw_atomic_long_set_release(9)
raw_atomic_long_add(9)
raw_atomic_long_add_return(9)
raw_atomic_long_add_return_acquire(9)
raw_atomic_long_add_return_release(9)
raw_atomic_long_add_return_relaxed(9)
raw_atomic_long_fetch_add(9)
raw_atomic_long_fetch_add_acquire(9)
raw_atomic_long_fetch_add_release(9)
raw_atomic_long_fetch_add_relaxed(9)
raw_atomic_long_sub(9)
raw_atomic_long_sub_return(9)
raw_atomic_long_sub_return_acquire(9)
raw_atomic_long_sub_return_release(9)
raw_atomic_long_sub_return_relaxed(9)
raw_atomic_long_fetch_sub(9)
raw_atomic_long_fetch_sub_acquire(9)
raw_atomic_long_fetch_sub_release(9)
raw_atomic_long_fetch_sub_relaxed(9)
raw_atomic_long_inc(9)
raw_atomic_long_inc_return(9)
raw_atomic_long_inc_return_acquire(9)
raw_atomic_long_inc_return_release(9)
raw_atomic_long_inc_return_relaxed(9)
raw_atomic_long_fetch_inc(9)
raw_atomic_long_fetch_inc_acquire(9)
raw_atomic_long_fetch_inc_release(9)
raw_atomic_long_fetch_inc_relaxed(9)
raw_atomic_long_dec(9)
raw_atomic_long_dec_return(9)
raw_atomic_long_dec_return_acquire(9)
raw_atomic_long_dec_return_release(9)
raw_atomic_long_dec_return_relaxed(9)
raw_atomic_long_fetch_dec(9)
raw_atomic_long_fetch_dec_acquire(9)
raw_atomic_long_fetch_dec_release(9)
raw_atomic_long_fetch_dec_relaxed(9)
raw_atomic_long_and(9)
raw_atomic_long_fetch_and(9)
raw_atomic_long_fetch_and_acquire(9)
raw_atomic_long_fetch_and_release(9)
raw_atomic_long_fetch_and_relaxed(9)
raw_atomic_long_andnot(9)
raw_atomic_long_fetch_andnot(9)
raw_atomic_long_fetch_andnot_acquire(9)
raw_atomic_long_fetch_andnot_release(9)
raw_atomic_long_fetch_andnot_relaxed(9)
raw_atomic_long_or(9)
raw_atomic_long_fetch_or(9)
raw_atomic_long_fetch_or_acquire(9)
raw_atomic_long_fetch_or_release(9)
raw_atomic_long_fetch_or_relaxed(9)
raw_atomic_long_xor(9)
raw_atomic_long_fetch_xor(9)
raw_atomic_long_fetch_xor_acquire(9)
raw_atomic_long_fetch_xor_release(9)
raw_atomic_long_fetch_xor_relaxed(9)
raw_atomic_long_xchg(9)
raw_atomic_long_xchg_acquire(9)
raw_atomic_long_xchg_release(9)
raw_atomic_long_xchg_relaxed(9)
raw_atomic_long_cmpxchg(9)
raw_atomic_long_cmpxchg_acquire(9)
raw_atomic_long_cmpxchg_release(9)
raw_atomic_long_try_cmpxchg(9)
raw_atomic_long_try_cmpxchg_acquire(9)
raw_atomic_long_try_cmpxchg_release(9)
raw_atomic_long_try_cmpxchg_relaxed(9)
raw_atomic_long_sub_and_test(9)
raw_atomic_long_dec_and_test(9)
raw_atomic_long_inc_and_test(9)
raw_atomic_long_add_negative(9)
raw_atomic_long_add_negative_acquire(9)
raw_atomic_long_add_negative_release(9)
raw_atomic_long_add_negative_relaxed(9)
raw_atomic_long_fetch_add_unless(9)
raw_atomic_long_add_unless(9)
raw_atomic_long_inc_not_zero(9)
raw_atomic_long_inc_unless_negative(9)
raw_atomic_long_dec_unless_positive(9)
raw_atomic_long_dec_if_positive(9)

mwah πŸ’‹ this page is from ./include/linux/atomic, dated October 2026, and its header is raw_atomic_...xchg_relaxed(9). periodt. πŸŽ€

πŸ“¦ where this page comes from