p As a rough heuristic, .Nm should be used for classes of objects of which there are maybe a few dozen instances but not a few thousand instances (e.g. autoconf devices, but not network flows) and on which there may be a mixture of long-term I/O waits, such as xyzread for a device xyz(4), and short-term fast operations, such as xyzioctl(IOC_READ_A_CPU_REG). .Sh FUNCTIONS l -tag -width abcd t Fn localcount_init "lc"
p Dynamically initialize localcount .Ar lc for use.
p No other operations can be performed on a localcount until it has been initialized. t Fn localcount_fini "lc"
p Release resources used by localcount .Ar lc . The caller must have already called .Fn localcount_drain . The localcount may not be used after .Fn localcount_fini has been called until it has been re-initialized by .Fn localcount_init . t Fn localcount_acquire "lc"
p Acquire a reference to the localcount .Ar lc . t Fn localcount_release "lc" "cv" "mtx"
p Release a reference to the localcount .Ar lc . If the localcount is currently being drained, the mutex .Ar mtx will be used to synchronize updates to the global reference count (i.e. the total across all CPUs). If the reference count goes to zero, .Fn localcount_release will broadcast availability of the condvar .Ar cv . t Fn localcount_drain "lc" "cv" "mtx"
p Wait for all references to the localcount .Ar lc to be released. The caller must hold the mutex .Ar mtx ; the mutex will be released during inter-CPU cross-calls (see .Xr xcall 9 ) and while waiting on the condvar .Ar cv . The same .Ar cv and .Ar mtx must be used with .Fn localcount_release .
p The caller must guarantee that no new references can be acquired with localcount_acquire before calling .Fn localcount_drain . For example, any object that may be found in a list and acquired must be removed from the list before calling .Fn localcount_drain . Once the localcount object .Ar lc is passed to .Fn localcount_drain , it must be passed to .Fn localcount_fini before any other re-use. .Sh CODE REFERENCES The core of the localcount implementation is in
a sys/kern/subr_localcount.c .
p The header file
a sys/sys/localcount.h describes the public interface, and interfaces that machine-dependent code must provide to support localcounts. .Sh SEE ALSO .Xr atomic_ops 3 , .Xr condvar 9 , .Xr mutex 9 , and .Xr psref 9 .Sh HISTORY The localcount primitives first appeared in .Nx 8.0 . .Sh AUTHORS This implementation of .Nm was written by .An -nosplit .An Taylor R. Campbell . This manual page was compiled by .An Paul Goyette . .Sh BUGS The .Nm facility does not provide any way to examine the reference count without actually waiting for the count to reach zero.
p Waiting for a .Nm reference count to reach zero is a one-shot operation. Once the .Nm has been waited for, no further operations are allowed until the .Nm has been re-initialized.