OpenBSD manual page server

Manual Page Search Parameters

SRPL_RC_INIT(9) Kernel Developer's Manual SRPL_RC_INIT(9)

srpl_rc_init, SRPL_HEAD, SRPL_ENTRY, SRPL_INIT, SRPL_FIRST, SRPL_NEXT, SRPL_FOLLOW, SRPL_FOREACH, SRPL_LEAVE, SRPL_RC_INITIALIZERsingly-linked shared reference pointer list

#include <sys/srp.h>

struct srpl_rc;

void
srpl_rc_init(struct srpl_rc *rc, void (*ref)(void *, void *), void (*unref)(void *, void *), void *ctx);

SRPL_HEAD(HEADNAME, TYPE);

SRPL_ENTRY(TYPE);

void
SRPL_INIT(SRPL_HEAD *sl);

void *
SRPL_FIRST(struct srp_ref *sr, SRPL_HEAD *sl);

void *
SRPL_NEXT(struct srp_ref *sr, struct TYPE *listelm, FIELDNAME);

void *
SRPL_FOLLOW(struct srp_ref *sr, struct TYPE *listelm, FIELDNAME);

SRPL_FOREACH(VARNAME, struct srp_ref *sr, SRPL_HEAD *sl, FIELDNAME);

void
SRPL_LEAVE(struct srp_ref *sr);

SRPL_RC_INITIALIZER(void (*ref)(void *, void *), void (*unref)(void *, void *), void *ctx);

The SRPL list macros build a linked list on top of shared reference pointers. This allows concurrent traversal of a linked list and access to the items on the list.

SRP lists are a generic type represented by a SRPL_HEAD. The elements inserted into the list must be structures that contain a SRPL_ENTRY field. Further, the elements must also support reference counting as insertion and removal operations can cause items to be temporarily referenced by multiple SRPs within the list at the same time.

() initialises the SRP list refcounts rc structure so it can be used to manage the reference counts on elements in the list. The insertion or removal of an element in an SRP list will increment the reference counts on elements within the list via calls to ref. As these references are released by the SRP infrastructure, the reference counts will be decremented by calls to unref. unref is also responsible for freeing the element when the reference count reaches 0. Both ref and unref will be called with ctx as their first argument and a pointer to the element as their second argument.

() initialises the SRP list sl to an empty state.

() accesses the first element in the SRP list sl and holds its reference via sr.

() accesses the element in the SRP list after listelm and holds its reference via sr.

() accesses the element in the SRP list after listelm and swaps the previous reference held via sr for the reference of the newly accessed item.

() creates a loop for traversing the list. Every call to SRPL_FOREACH() must have a corresponding call to SRPL_LEAVE() to release references to the list and its elements.

() releases references to the list and its elements held by previous calls to SRPL_FIRST(), SRPL_NEXT(), SRPL_FOLLOW(), or SRPL_FOREACH().

An srpl_rc declaration can be initialised with the () macro.

SRPL_INIT(), SRPL_FIRST(), SRPL_NEXT(), SRPL_FOLLOW(), SRPL_FOREACH(), and SRPL_LEAVE() may be called during autoconf, from process context, or from interrupt context.

srpl_rc_init(), may be called during autoconf or from process context.

SRPL_FIRST(), SRPL_NEXT(), and SRPL_FOLLOW() return a pointer to elements in the SRP list, or NULL if there are no more elements.

SRPL_FIRST_LOCKED(9)

The srp API was originally written by Jonathan Matthew <jmatthew@openbsd.org> and David Gwynne <dlg@openbsd.org>. The SRP list API first appeared in OpenBSD 5.9.

November 21, 2016 OpenBSD-current