raw_atomic_dec_and_test(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… NAME

raw_atomic_dec_and_test β€” atomic decrement and test if zero with full ordering πŸŽ€

okay so this is the raw flavour of the decrement-and-test vibe check, and she is iconic for exactly one reason: she's built for the places where normal functions are not allowed to party. more on that below, bestie πŸ’–


✨ SYNOPSIS

bool raw_atomic_dec_and_test (atomic_t *v );

like, that's the whole thing. one argument, returns a bool, no drama ✨


πŸŽ€ ARGUMENTS

  • v β€” pointer to atomic_t 🌸 that's it, that's the girl. hand her a pointer to an atomic_t and she'll do her lil thing.

πŸ’– DESCRIPTION

Atomically updates v to (v - 1) with full ordering. πŸ”₯

so like, the decrement happens atomically β€” nobody can sneak in mid-subtraction and see a cursed half-decremented state, no cap β€” and the "full ordering" part means the memory ordering around it is the strict/whole version, not the relaxed little sister version. the way that (v - 1) is literally in the docs, I love consistency 🫢

the important tea β˜•: it's safe to use in noinstr code β€” that's the special-est of special contexts β€” but prefer atomic_dec_and_test elsewhere. raw_* is the fallback-flavoured one, so outside of noinstr you should be using the regular name. it's giving "I'm here for a specific job and that job is not everywhere" πŸ’…

🌈 RETURN

  • true β€” if the resulting value of v is zero ⭐
  • false β€” otherwise πŸ™ˆ

so you can slam it straight into an if and let it tell you when the counter has fully hit the floor. periodt.


πŸ¦‹ SEE ALSO

Kernel file: ./include/linux/atomic/atomic-arch-fallback.h πŸ‘‘

and the whole extended family, fr fr β€” every single one of these is a real reference, no skipping:

the raw_atomic_ basics

raw_atomic_ adds

raw_atomic_ subs

raw_atomic_ incs

raw_atomic_ decs

raw_atomic_ bitwise shenanigans (and / andnot)

raw_atomic_ bitwise shenanigans (or / xor)

raw_atomic_ exchanges

raw_atomic_ compare-and-exchange

raw_atomic_ and-test / negative / unless crew

the 64-bit raw_atomic64_ basics

raw_atomic64_ adds

raw_atomic64_ subs

raw_atomic64_ incs

raw_atomic64_ decs

raw_atomic64_ bitwise (and / andnot)

raw_atomic64_ bitwise (or / xor)

raw_atomic64_ exchanges

raw_atomic64_ compare-and-exchange

raw_atomic64_ and-test / negative / unless crew


and that's the whole page, bestie 🫢✨ this one came from ./include/linux/atomic, dated October 2026 β€” go forth and decrement responsibly πŸ’–πŸŽ€πŸ¦‹

πŸ“¦ where this page comes from