refcount_dec_if_one(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… refcount_dec_if_one

okay bestie, welcome to the kernel API manual β€” yes it's that Kernel API Manual vibe, and yes this page is a little gem. It's called refcount_dec_if_one and it's literally the "decrement a refcount if it is 1" girlie. No cap. πŸŽ€


✨ SYNOPSIS ✨

bool refcount_dec_if_one (refcount_t *r );

that's the whole signature, she's compact, she's iconic, she takes exactly one argument and she gives you back a bool. periodt. πŸ¦‹


🌸 ARGUMENTS 🌸

  • r β€” the refcount πŸ’– (yes, that's it, that's the whole argument, she's the pointer to the refcount_t you're messing with)

🧚 DESCRIPTION 🧚

okay so here's the tea: there is no atomic_t counterpart for this one. Not a thing. It attempts a 1 -> 0 transition and returns whether that worked or not. that's the whole assignment. πŸ”₯

Like every other decrement operation in the family, it provides release memory order and provides a control dependency. So like… she's not just cute, she's got proper ordering semantics. main character energy tbh. πŸ‘‘

You can use it like a try-delete operator β€” that's literally its whole purpose. And listen, this explicit case is provided (and not just done with cmpxchg in generic) on purpose, because using cmpxchg in generic would allow implementing unsafe operations. So the restriction is a feature, not a bug, iykyk. πŸ’…

⚠️ fr fr, do not try to sneak a generic cmpxchg version in here β€” the whole point of exposing this exact helper is to prevent unsafe stuff from being built on top of it.

⭐ RETURN ⭐

  • true if the resulting refcount is 0 πŸŽ‰
  • false otherwise πŸ™ˆ

that's it. binary. no in-between. slay.


πŸ¦‹ SEE ALSO πŸ¦‹

go read those too, bestie, they're the rest of the friend group. 🌈


mwah πŸ’œ β€” this page lives in ./lib, it's dated October 2026, and it goes by refcount_dec_if_one(9). stay safe out there and always decrement responsibly 🫢✨

πŸ“¦ where this page comes from