atomic_dec_and_lock(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… 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 🌈


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