atomic_cmpxchg_relaxed(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… atomic_cmpxchg_relaxed β€” Kernel API Manual, section 9 πŸŽ€

okay so bestie, we're in the Kernel API Manual today and the star of the show is atomic_cmpxchg_relaxed(9). it's the chill, low-key sibling of the compare-and-swap family and honestly it ate. let's get into it ✨


🌸 NAME 🌸

atomic_cmpxchg_relaxed β€” atomic compare and exchange with relaxed ordering

like, you compare, you exchange, and you do not stress about ordering. she's laid back. she's relaxed. she's got main character energy πŸ’…


✨ SYNOPSIS ✨

int atomic_cmpxchg_relaxed (atomic_t *v , int old , int new );

πŸ¦‹ ARGUMENTS πŸ¦‹

  • v β€” pointer to atomic_t. this is the thing we're messing with 🫢
  • old β€” int value to compare with. the "is it you, babe?" value πŸ‘€
  • new β€” int value to assign. the "okay you're you, here's your new fit" value πŸ’–

πŸ‘‘ DESCRIPTION πŸ‘‘

If (v == old), atomically updates v to new with relaxed ordering. Otherwise, v is not modified and relaxed ordering is provided.

so fr fr: match happens β†’ v becomes new, all in one atomic little moment, relaxed ordering the whole way. no match β†’ v stays exactly as it was, and you still get relaxed ordering out of the deal. no cap πŸ’€

⚠️ Unsafe to use in noinstr code; use raw_atomic_cmpxchg_relaxed there. like genuinely, do not do it. noinstr code has rules and this is not the function for that party πŸ™ˆ

⭐ RETURN ⭐

The original value of v. that's it, that's the tea πŸ“ β€” remember, it's the value from before anything changed, icon behavior πŸ’œ


🌈 SEE ALSO 🌈

Kernel file ./include/linux/atomic/atomic-instrumented.h β€” and okay the whole entire friend group shows up here, so buckle up bestie, we're listing every single one πŸ’–


and that's the whole page bestie!! 🧚 this lil cutie lives in ./include/linux/atomic, dated October 2026, and you can find her filed under atomic_cmpxchg_relaxed(9). go forth and swap atomically, but relaxed, obviously πŸ’–βœ¨πŸŽ€

πŸ“¦ where this page comes from