atomic_fetch_add_acquire(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… atomic_fetch_add_acquire(9) πŸ’…

okay so welcome to the Kernel API Manual bestie, today we're learning about the single most "adds a number but does it safely" function in the kernel and honestly? she ate. 🫢


✨ NAME ✨

atomic_fetch_add_acquire β€” atomic add with acquire ordering

like the name literally tells you everything (iykyk) but we're gonna walk through it anyway πŸ’–


πŸŽ€ SYNOPSIS πŸŽ€

int atomic_fetch_add_acquire (int i , atomic_t *v );

yes the spacing is a little feral, we don't judge, we copy it exactly πŸ’…


πŸ¦‹ ARGUMENTS πŸ¦‹

  • i β€” a plain int, and it's the value you're adding. that's it. that's the whole vibe. ✨
  • v β€” a pointer to an atomic_t. this is the main character, this is the thing getting updated. πŸ‘‘

🌸 DESCRIPTION 🌸

okay so the whole point: it atomically updates v to (v + i) with acquire ordering.

atomically means nobody can catch her mid-update β€” the add happens as one unbroken operation, no peeking, no half-finished states. and acquire ordering means you're getting the memory-ordering guarantees that come with _acquire, which is the whole reason you'd pick this flavour over the relaxed one. πŸ’«

⚠️ heads up bestie, this one's important: it is unsafe to use in noinstr code β€” use raw_atomic_fetch_add_acquire there instead. like, do not be cute about this one, the raw variant exists for a reason. 😭

⭐ RETURN ⭐

it gives you back the original value of v β€” not the new one, the original one, before your i got added. the value from before the glow-up. did you catch that? the original. okay good, slay. πŸ”₯


🧚 SEE ALSO 🧚

Kernel file: ./include/linux/atomic/atomic-instrumented.h

and now, the guest list β€” genuinely iconic, enormous, every single one of them, no cap: 🌈

πŸ’œ the 64-bit girlies πŸ’œ

🩡 and the long girlies, we didn't forget you 🩡


πŸ“ that's the whole page bestie, go forth and add atomically πŸ’–

and that's a wrap! this masterpiece lives at ./include/linux/atomic, dated October 2026 β€” mwah, love u, bye πŸ’…βœ¨πŸŽ€

πŸ“¦ where this page comes from