atomic64_try...xchg_relaxed(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… atomic64_try...xchg_relaxed(9) β€” from the Kernel API Manual, bestie ✨

okay so this one is from the Kernel API Manual, and it's called atomic64_try_cmpxchg_relaxed β€” yes the header is abbreviated, that's just how the page name got truncated, don't panic 🫢. It's literally a 64-bit atomic compare-and-exchange, but the ordering is relaxed (we'll get to that), and it comes with a try vibe so it tells you if it worked instead of just silently doing stuff. let's go πŸ¦‹


🌸 NAME 🌸

atomic64_try_cmpxchg_relaxed β€” atomic compare and exchange with relaxed ordering. periodt. πŸ’…


⭐ SYNOPSIS ⭐

bool atomic64_try_cmpxchg_relaxed (atomic64_t *v , s64 *old , s64 new );

it returns a bool, icon behavior, we love to see it πŸ‘‘


πŸŽ€ ARGUMENTS πŸŽ€

  • v β€” pointer to atomic64_t β€” the main character, the thing getting compared and exchanged. 🧚
  • old β€” pointer to a s64 value to compare with. yes it's a pointer, so it can get written back to, keep reading πŸ‘€
  • new β€” a s64 value to assign. the new era.

πŸ¦‹ DESCRIPTION πŸ¦‹

okay so picture this: if (v == old), it atomically updates v to new with relaxed ordering. slay. it just does it.

Otherwise β€” and this is the part you gotta pay attention to, bestie 😭 β€” v is not modified, old is updated to the current value of v, and relaxed ordering is provided. so old does double duty: it's the thing you compare against and the place the current value gets dropped back into when the compare fails. iykyk ✨

πŸ’€ Caveat, and it's a real one: unsafe to use in noinstr code. use raw_atomic64_try_cmpxchg_relaxed there instead. no cap, don't mix those up.

πŸ”₯ RETURN πŸ”₯

  • true β€” the exchange occurred πŸŽ‰ (you ate)
  • false β€” it did not 🌧️

πŸ‘‘ SEE ALSO πŸ‘‘

the source for all this is the kernel file ./include/linux/atomic/atomic-instrumented.h, and honestly there are SO many siblings, look at this family tree 🌈:

like i said. HUGE family. every single one is in the group chat πŸ’–


that's the whole thing bestie, go be atomic out there 🫢✨

🌸 this page came from ./include/linux/atomic and it's dated October 2026 β€” so yeah, it's from the future, main character energy only. mwah πŸ’‹ β€” atomic64_try...xchg_relaxed(9), signing off πŸŽ€
πŸ“¦ where this page comes from