REFCOUNT(9)
π REFCOUNT(9) π
okay bestie, we're in the Kernel Developer's Manual today and we are talking about refcount β yes, the whole lil family: refcount_init, refcount_acquire, refcount_release. they manage a simple reference counter. that's it. that's the vibe. π
β¨ NAME β¨
refcount, refcount_init, refcount_acquire, refcount_release β manage a simple reference counter π
πΈ SYNOPSIS πΈ
like, here's the receipts:
#include <sys/param.h>
#include <sys/refcount.h>
void
refcount_init(volatile u_int *count, u_int value);
void
refcount_acquire(volatile u_int *count);
bool
refcount_release(volatile u_int *count);
π¦ DESCRIPTION π¦
so the refcount functions are literally just an API to manage a simple reference counter. that's the whole job. π
the caller provides the storage for the counter in an unsigned integer. a pointer to this integer gets passed in via count. usually the counter is used to manage the lifetime of an object and it's stored as a member of the object. classic. icon behaviour. β¨
refcount_init() sets the initial value of the counter to value. it's normally used when you're creating a reference-counted object. brand new object, brand new counter, we love a fresh start π«Ά
refcount_acquire() is how you acquire a new reference. now listen β the caller is responsible for making sure it holds a valid reference while obtaining a new reference. for example, if an object is stored on a list and the list holds a reference on the object, then holding a lock that protects the list gives you sufficient protection for acquiring a new reference. iykyk. π
refcount_release() releases an existing reference. it returns true if the reference being released was the last reference; otherwise it returns false. no cap. π
β οΈ note bestie, and this part is IMPORTANT: these routines do not provide any inter-CPU synchronization, data protection, or memory ordering guarantees β except for managing the counter. that's literally it. the caller is responsible for any additional synchronization needed by consumers of any containing objects. AND the caller is also responsible for managing the life cycle of any containing objects, including explicitly releasing any resources when the last reference is released. do not forget that part fr fr π
π RETURN VALUES π
the refcount_release function returns true when releasing the last reference and false when releasing any other reference. simple. slay. β
π HISTORY π
these functions were introduced in FreeBSD 6.0. throwback era, we respect the elders π
and that's the whole page bestie!! this little cutie came to you from the Debian build, dated July 21, 2019 β yeah she's a lil vintage but she still ate π β¨ go forth and count your references responsibly, mwah π«Άπ
π¦ where this page comes from
- debian bookworm: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- debian trixie: freebsd-manpages 12.2-2 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu jammy: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu noble: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu questing: freebsd-manpages 12.2-2
- ubuntu resolute: freebsd-manpages 12.2-2build1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu stonking: freebsd-manpages 12.2-2build1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- Copyright (c) 2009 Hudson River Trading LLC
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms