refcount_inc_not_zero(9)
π 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 π₯
trueif the increment was successful βfalseotherwise π
π SEE ALSO π
kernel file ./include/linux/refcount.h β and the whole refcount friend group, all together now:
refcount_set(9)refcount_set_release(9)refcount_read(9)refcount_add_not_zero(9)refcount_add_not_zero_acquire(9)refcount_add(9)refcount_inc_not_zero_acquire(9)refcount_inc(9)refcount_sub_and_test(9)refcount_dec_and_test(9)refcount_dec(9)
π 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
- 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