refcount_inc_not_zero(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’– refcount_inc_not_zero β€” kernel API manual, bestie edition πŸ’–

okay so this one is a <pink>kernel API manual</pink> page, and honestly? it's a little baddie. let's get into it 🫢


✨ NAME ✨

refcount_inc_not_zero β€” increment a refcount unless it is 0 πŸ’…

like, it bumps the counter only if the counter isn't already sitting at zero. no zero, no bump. periodt.

🌸 SYNOPSIS 🌸

bool refcount_inc_not_zero (refcount_t *r );

πŸŽ€ ARGUMENTS πŸŽ€

  • r β€” the refcount to increment. that's the one, that's the girl πŸ’–

πŸ¦‹ DESCRIPTION πŸ¦‹

so it's similar to atomic_inc_not_zero, but plot twist: it will saturate at REFCOUNT_SATURATED and WARN. so if you keep pushing it past the limit, it doesn't just keep going β€” it maxes out and then yells at you in the logs 😭 iconic behaviour ngl.

it provides no memory ordering. like, none. zero. the assumption is that the caller has already guaranteed the object memory is stable (RCU, etc.) β€” so that part is on you, bestie πŸ™ˆ. it does provide a control dependency and thereby orders future stores. see the comment on top πŸ‘€ (iykyk).

no cap: if you're reaching for this expecting it to do memory-ordering work for you, it is not doing that. caller guarantees stability of the object memory. that's the deal.

πŸ”₯ RETURN πŸ”₯

  • true if the increment was successful ⭐
  • false otherwise πŸ’€

πŸ‘‘ SEE ALSO πŸ‘‘

kernel file ./include/linux/refcount.h β€” and the whole refcount friend group, all together now:


🌈 that's the whole page, bestie, we ate and left no crumbs. this little number lives in ./include/linux, and it's dated October 2026 β€” so yes, it's from the future, main character energy fr fr πŸ§šπŸ’œ

πŸ“¦ where this page comes from