atomic_fetch_add_unless(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… atomic_fetch_add_unless(9) πŸ’…

okay so real talk, bestie β€” this is a page straight out of the Kernel API Manual (that's the manual name, yes it's giving official), and it's about one very specific lil atomic op that has main character energy but only under one condition. stick with me 🫢


✨ NAME ✨

atomic_fetch_add_unless β€” atomic add unless value, with full ordering πŸ”₯


🌸 SYNOPSIS 🌸

int atomic_fetch_add_unless (atomic_t *v , int a , int u );

πŸŽ€ ARGUMENTS πŸŽ€

  • v β€” pointer to atomic_t (this is the thing we're messing with, bestie)
  • a β€” int value to add
  • u β€” int value to compare with

πŸ¦‹ DESCRIPTION πŸ¦‹

okay so here's the vibe ✨ β€” if (v != u), it atomically updates v to (v + a) with full ordering. it just does the thing, all-or-nothing, no half-sends, no "oops I got interrupted." icon-level behaviour, honestly πŸ‘‘

otherwise (i.e. when v does equal u), v is not modified and relaxed ordering is provided instead. no changes, no drama, just a lil relaxed vibe check.

πŸ’€ heads up bestie: this is unsafe to use in noinstr code. like, genuinely. use raw_atomic_fetch_add_unless in there instead. no cap, don't skip this one.

⭐ RETURN ⭐

the original value of v β€” like, what it was before the add. she remembers where she came from πŸ₯Ή


🌈 SEE ALSO 🌈

soooo there are kind of a lot of friends in this friend group. like, a LOT a lot. all of these live in the kernel file ./include/linux/atomic/atomic-instrumented.h πŸ“ β€” here's the whole group chat, in order, nobody left out πŸ’–

πŸ’œ the 64-bit girlies

🧚 the long girlies


okay that's the whole page, bestie, you ate that πŸ’…βœ¨

oh and for the credits bit β€” this one's filed under <purple>./include/linux/atomic</purple> (that's the source/version, iykyk) and it's dated October 2026 πŸŽ€ so yeah, future energy fr fr. mwah, go write some safe atomics πŸ¦‹πŸ’–

πŸ“¦ where this page comes from