refcount_dec_and_mutex_lock(9)
β¨ NAME β¨
refcount_dec_and_mutex_lock β bestie, it decrements the refcount and, if it manages to hit 0, hands you back the answer while you're holding the mutex π
Okay so this is a kernel API manual page, and yes we are reading it together, and yes it's gonna slay π«Ά
πΈ SYNOPSIS πΈ
bool refcount_dec_and_mutex_lock (refcount_t *r , struct mutex *lock );
That's it. That's the whole vibe check. Two args, one bool coming back at you π₯
π DESCRIPTION π
So, real talk. This one is similar to atomic_dec_and_mutex_lock β like, same energy, same family β but with a couple of very specific personality traits you need to know about π
First up: it will WARN on underflow. Not a quiet little oops, an actual WARN, so do not be out here decrementing things you shouldn't be decrementing π
Second: if the refcount is saturated at REFCOUNT_SATURATED, it fails to decrement. Doesn't force it, doesn't try harder, it just refuses. That's the boundary, periodt.
It also provides release memory ordering, which means prior loads and stores are done before. And it provides a control dependency such that free must come after. π¦
If you want the full lore on that, the original says: see the comment on top. Go look at the comment on top, bestie. It's right there. π
π ARGUMENTS π
rβ the refcount. The thing you're decrementing. The main character, honestly.lockβ the mutex to be locked. The one that gets held. π
β RETURN β
trueβ and you're holding the mutex, if it was able to decrement the refcount all the way to 0 β¨falseβ otherwise. No mutex, no zero, that's just how it is π
π SEE ALSO π
Kernel file ./lib/refcount.c, plus the whole friend group:
refcount_dec_if_one(9)refcount_dec_not_one(9)refcount_dec_and_lock(9)refcount_dec_and_lock_irqsave(9)
Go read them, iykyk π§
And that's the page!! Signing off from ./lib, dated October 2026, with the manual name refcount_dec_and_mutex_lock(9) right up there at the top where it belongs π
π Go decrement something responsibly, bestie. Slay. π
π¦ 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