SRP_ENTER(9)
okay so welcome to SRP_ENTER(9) β the Kernel Developer's Manual page for shared reference pointers, and bestie, it's giving lock free main character energy π
β¨
β¨ NAME β¨
SRP_ENTER(9) covers srp_init, srp_gc_init, srp_update, srp_update_locked, srp_swap, srp_swap_locked, srp_enter, srp_follow, srp_leave, srp_get_locked, srp_finalize, srp_gc_finalize, SRP_INITIALIZER, and SRP_GC_INITIALIZER β aka shared reference pointers. π«Ά
π SYNOPSIS π
include this header and you're in, bestie:
#include <sys/srp.h>
void
srp_init(struct srp *p);
void
srp_gc_init(struct srp_gc *gc, void (*dtor)(void *, void *), void *ctx);
void *
srp_swap(struct srp *p, void *v);
void *
srp_swap_locked(struct srp *p, void *v);
void
srp_update(struct srp_gc *gc, struct srp *p, void *v);
void
srp_update_locked(struct srp_gc *gc, struct srp *p, void *v);
void *
srp_enter(struct srp_ref *sr, struct srp *p);
void *
srp_follow(struct srp_ref *sr, struct srp *n);
void
srp_leave(struct srp_ref *sr);
void *
srp_get_locked(struct srp *p);
void
srp_finalize(void *v, const char *wmesg);
void
srp_gc_finalize(struct srp_gc *gc);
SRP_INITIALIZER();
SRP_GC_INITIALIZER(void (*dtor)(void *, void *), void *ctx);
π¦ DESCRIPTION π¦
An srp structure represents a pointer or reference to an object in memory. The srp API provides concurrent lock free access to these objects, and can guarantee that the data isn't destroyed while that reference is in use. It does not prevent concurrent modification of the referenced object. π
srp_init()β initialises thesrpstructurepto an empty state. π«§srp_gc_init()β initialises thesrp_gcstructuregcso it can be used as a garbage collector for data that gets referenced bysrpstructures. An update to ansrpstructure will cause the old data to be destroyed when it is no longer referenced by any CPU in the system. The old data will be destroyed by the garbage collector by a call todtorwithctxas the first argument and the pointer to the data as the second argument. ποΈsrp_update()andsrp_update_locked()β replace the data referenced by thesrpstructpwith the data referenced byv. When the original data is no longer in use, it will be destroyed by the garbage collectorgc.srp_update()uses atomic CPU operations to change the references.srp_update_locked()may be used if modifications topare already serialised by the caller. Bothsrp_update()andsrp_update_locked()may sleep. π΄srp_swap()andsrp_swap_locked()β replace the data referenced by thesrpstructpwith the data referenced byv. When clearing or replacing the last reference to a data structure,srp_finalize()must be used to ensure that the data is no longer in use via anysrpstructures.srp_swap()uses atomic CPU operations to change the reference.srp_swap_locked()may be used if modifications topare already serialised by the caller. πsrp_enter()β returns a pointer to a data structure referenced by thesrpstructpand guarantees it will remain available for use until it is released with a call tosrp_leave()orsrp_follow(). The reference is held viasr. π«Άsrp_follow()β replaces the reference held viasrwith a reference to the data structure represented byp. πͺsrp_leave()β releases the reference held viasrand makes it available for garbage collection. πsrp_get_locked()β provides access to the data referenced by thesrppif the caller has excluded updates top. πsrp_finalize()β sleeps until there are no longer any references tovvia anysrpstructure in the system. π€srp_gc_finalize()β sleeps until all references to data bysrpstructures using the garbage collectorgchave completed. That in turn means thegcstructure will no longer be referenced and can itself be destroyed. π§Ή
A srp structure declaration can be initialised with the SRP_INITIALIZER() macro. β¨
A srp_gc structure declaration can be initialised with the SRP_GC_INITIALIZER() macro. Data will be destroyed by the garbage collector by a call to dtor with ctx as the first argument and the pointer to the data as the second argument. π
π CONTEXT π
context check, bestie β here's where you can call what:
srp_init(),srp_gc_init(),srp_update(),srp_update_locked(),srp_get_locked(),srp_finalize(), andsrp_gc_finalize()β can be called during autoconf or from process context. π οΈsrp_swap(),srp_swap_locked(),srp_enter(),srp_follow(), andsrp_leave()β can be called during autoconf, from process context, or from interrupt context. β‘
π RETURN VALUES π
srp_swap()andsrp_swap_locked()β return a pointer to the previous value referenced by thesrpstructurep. πsrp_enter(),srp_follow(), andsrp_get_locked()β return a pointer to the data referenced by thesrpstructureporNULL. π«‘
π HISTORY π
The srp API was originally written by Jonathan Matthew <jmatthew@openbsd.org> and David Gwynne <dlg@openbsd.org>. The srp API first appeared in OpenBSD 5.8. π
π xoxo, Debian β July 27, 2022 β SRP_ENTER(9) signing off, periodt. π
π¦ where this page comes from
- nixpkgs unstable: cvs-export
- Copyright (c) 2015 David Gwynne <dlg@openbsd.org>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms