reference count API
refcnt *r, const char
The refcnt API provides simple reference counters that can be used to manage the lifetime of a shared object.
sets the initial value of the counter to 1 to account for the caller's
reference to the object.
is used to acquire a new reference. It is the responsibility of the caller
to guarantee that it holds a valid reference before taking a new
is used to release an existing reference.
is used to release an existing reference and wakes up a process that is
currently waiting in
refcnt_finalize() for all the
references to released.
releases the caller's reference and sleeps until all the other references to
the relevant object have been released. There may only be one caller to
refcnt_finalize() per refcnt
refcnt_finalize() order prior memory loads and
stores before the release of the reference. The functions enforce control
dependency so that after the final reference has been released, subsequent
loads and stores happen after the release. These ensure that concurrent
accesses cease before the object's destructor runs and that the destructor
sees all updates done during the lifetime of the object.
returns a snapshot of the counter value. Its use is discouraged, code should
refcnt_shared() whenever possible.
initialises a declaration of a refcnt to 1.
refcnt_read() can be called during autoconf, from
process context, or from interrupt context.
refcnt_finalize() can be called from
refcnt_rele() returns a non-zero value if
the last reference has been released, otherwise 0.
refcnt_shared() returns a non-zero value
if the object has multiple references, otherwise 0.
refcnt_read() returns a snapshot of the