atomic_dec_and_lock(9)
π atomic_dec_and_lock (Kernel API Manual, section 9)
okay bestie, gather round, because this little function is genuinely iconic and also lowkey doing the most important job in the whole kernel π
β¨ NAME β¨
atomic_dec_and_lock β lock on reaching reference count zero π₯
like, that's it. that's the whole vibe. it counts down and then grabs the lock the moment things hit zero. no cap.
πΈ SYNOPSIS πΈ
int atomic_dec_and_lock (atomic_t *atomic , spinlock_t *lock );
(no fr, copy it exactly like that, spaces and all, i don't make the rules π )
π¦ ARGUMENTS π¦
atomicβ the atomic counter. she's the one getting decremented, main character energy honestly πlockβ the spinlock in question. the one that might get locked, depending on how the countdown goes π
π DESCRIPTION π
okay so here's the tea β
atomic_dec_and_lock decrements atomic by 1. that's the easy part.
if the result is 0, it returns true and locks lock. like β the moment the count hits zero, she snatches that spinlock. slay π
β¨
it returns false for all other cases. that's it, that's the whole story. no lock, no drama, just a polite false and she moves on π
the way that this is literally the reference-count-hits-zero-and-we-lock pattern in one tidy callβ¦ obsessed π«Ά
π SEE ALSO π
- Kernel file
./include/linux/spinlock.h spin_is_locked(9)
and that's the page, bestie! π¦ this little beauty lives in ./include/linux and the manual's dated October 2026 β so go forth, decrement responsibly, and may your reference counts always land exactly on zero at the right moment πβπ§
π¦ where this page comes from
- nixpkgs unstable: linux-manual 7.3.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms