atomic_dec_return_acquire(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… atomic_dec_return_acquire(9) β€” like, the Kernel API Manual page, bestie

okay so this is from the Kernel API Manual (section 9, kernel dev girlies know) and it's genuinely one of my fave little atomic ops, no cap. Let me walk you through it 🫢


✨ NAME ✨

atomic_dec_return_acquire β€” atomic decrement with acquire ordering ✨ it takes one off and also gives you acquire ordering, she's doing two jobs and slaying both πŸ’…


🌸 SYNOPSIS 🌸

int atomic_dec_return_acquire (atomic_t *v );

like that's literally it, one pointer, so clean πŸŽ€


πŸ¦‹ ARGUMENTS πŸ¦‹

  • v β€” pointer to atomic_t πŸ’– yes bestie, it's a pointer, and it points at an atomic_t, that's the whole vibe

πŸ‘‘ DESCRIPTION πŸ‘‘

So what she does: atomically updates v to (v - 1) with acquire ordering. Atomically!! meaning nobody can catch her halfway through, and acquire ordering means the memory ordering is also handled for you. iconic behaviour honestly ⭐

⚠️ Unsafe to use in noinstr code β€” use raw_atomic_dec_return_acquire there. Not me warning you twice, but like, genuinely, don't do it πŸ™ˆ use the raw_ one in noinstr code, periodt.

πŸ”₯ RETURN πŸ”₯

The updated value of v. so like, the value after the decrement, which is the only sensible thing to return, we love a function that knows what it's about πŸ’œ


🌈 SEE ALSO 🌈

she lives in the kernel file ./include/linux/atomic/atomic-instrumented.h, and the whole atomic family is here, I'm obsessed, look at all these sisters 🧚


and that's the whole page, bestie πŸŽ€ go decrement something atomically, iykyk πŸ’–

mwah πŸ’‹ this came out of the kernel file ./include/linux/atomic, dated October 2026, as brought to you by the Kernel API Manual β€” catch you in the next one, love u 🫢

πŸ“¦ where this page comes from