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

# NAME

`srpl_rc_init`, `SRPL_HEAD`, `SRPL_ENTRY`, `SRPL_INIT`, `SRPL_FIRST`, `SRPL_NEXT`, `SRPL_FOLLOW`, `SRPL_FOREACH`, `SRPL_LEAVE`, `SRPL_RC_INITIALIZER` — singly-linked shared reference pointer list

# SYNOPSIS

`#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);

# DESCRIPTION

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.

`srpl_rc_init`() 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.

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

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

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

`SRPL_FOLLOW`() 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.

`SRPL_FOREACH`() 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.

`SRPL_LEAVE`() 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 `SRPL_RC_INITIALIZER`() macro.

# CONTEXT

`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.

# RETURN VALUES

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

# SEE ALSO

SRPL_FIRST_LOCKED(9)

# HISTORY

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 | Debian