refcount_dec_and_mutex_lock(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

✨ 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:

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