SRPL_RC_INIT(9)

πŸ“¦ in nixpkgs unstable

πŸ’… SRPL_RC_INIT β€” singly-linked shared reference pointer list ✨

okay so picture this: a man page, but make it a group chat. This lil cutie lives in section 9 of the Kernel Developer's Manual, and it's all about the SRPL family β€” srpl_rc_init, SRPL_HEAD, SRPL_ENTRY, SRPL_INIT, SRPL_FIRST, SRPL_NEXT, SRPL_FOLLOW, SRPL_FOREACH, SRPL_LEAVE, and SRPL_RC_INITIALIZER. It's giving "singly-linked shared reference pointer list" and honestly? iconic. πŸŽ€


✨ 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, and the whole point of that is concurrent traversal πŸ”₯ β€” you can walk the list and touch the items on it at the same time, no cap.

SRP lists are a generic type, and they're represented by a SRPL_HEAD. Any element you insert has to be a structure that contains a SRPL_ENTRY field. Also β€” and this part is important, bestie β€” those elements must support reference counting too, because insertion and removal operations can cause items to be temporarily referenced by multiple SRPs within the list at the same time. It's a whole vibe where an element gets a little crowd of references around it for a sec. πŸ’…

  • 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. When you insert or remove an element in an SRP list, the reference counts on elements within the list get incremented via calls to ref. As these references are released by the SRP infrastructure, the reference counts get decremented by calls to unref. And unref is also responsible for freeing the element when the reference count reaches 0 β€” so yes, it's doing double duty, main character energy fr. Both ref and unref get 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. clean slate, fresh start, we love to see it ✨
  • 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. cute little trade-off, no notes 🫢
  • SRPL_FOREACH() β€” creates a loop for traversing the list. Every single call to SRPL_FOREACH() must have a corresponding call to SRPL_LEAVE() to release references to the list and its elements. no skipping, no ghosting your references 😭
  • SRPL_LEAVE() β€” releases references to the list and its elements held by previous calls to SRPL_FIRST(), SRPL_NEXT(), SRPL_FOLLOW(), or SRPL_FOREACH().

And if you've got an srpl_rc declaration, you can initialise it with the SRPL_RC_INITIALIZER() macro. 🌸


🌈 CONTEXT 🌈

Where you're allowed to call these, iykyk.

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. very flexible, very demure πŸ’–

srpl_rc_init() may be called during autoconf or from process context. (slightly stricter invite list, but she's still slay.)


⭐ 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. so if you get NULL, that's your sign the list said "that's all bestie" πŸ‘‘


πŸŽ€ 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> β€” legends, honestly. The SRP list API first appeared in OpenBSD 5.9. 🧚


and that's the whole page, bestie! this cutie came from the Debian crew, dated November 21, 2016, and it's out here doing the most in SRPL_RC_INIT(9). go traverse something safely, and don't forget to SRPL_LEAVE() β€” periodt πŸ’œπŸŒΈπŸ¦‹

πŸ“¦ where this page comes from
  • nixpkgs unstable: cvs-export
  • πŸ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms