aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKonstantin Belousov <kib@FreeBSD.org>2023-05-14 01:40:08 +0000
committerKonstantin Belousov <kib@FreeBSD.org>2023-06-05 08:35:01 +0000
commit135bc1d49de598a8c1c0b679e70265e01d08beea (patch)
tree60957e9a546370bdf8defe0101888e58c3acaca1
parentd4fb56c08fb971916d87483f74ae3f1b4adf2e91 (diff)
downloadsrc-135bc1d49de598a8c1c0b679e70265e01d08beea.tar.gz
src-135bc1d49de598a8c1c0b679e70265e01d08beea.zip
unr(9): document iterators
(cherry picked from commit ea95173dbb3b67019a83155e55f798d4618f18c7)
-rw-r--r--share/man/man9/unr.946
1 files changed, 45 insertions, 1 deletions
diff --git a/share/man/man9/unr.9 b/share/man/man9/unr.9
index c0cf44b9033e..201717ccdfd2 100644
--- a/share/man/man9/unr.9
+++ b/share/man/man9/unr.9
@@ -34,7 +34,10 @@
.Nm delete_unrhdr ,
.Nm alloc_unr ,
.Nm alloc_unr_specific ,
-.Nm free_unr
+.Nm free_unr ,
+.Nm create_iter_unr ,
+.Nm next_iter_unr ,
+.Nm free_iter_unr
.Nd "kernel unit number allocator"
.Sh SYNOPSIS
.In sys/systm.h
@@ -56,6 +59,12 @@
.Fn alloc_unr_specific "struct unrhdr *uh" "u_int item"
.Ft void
.Fn free_unr "struct unrhdr *uh" "u_int item"
+.Ft void *
+.Fn create_iter_unr "struct unrhdr *uh"
+.Ft int
+.Fn next_iter_unr "void *handle"
+.Ft void
+.Fn free_iter_unr "void *handle"
.Sh DESCRIPTION
The kernel unit number allocator is a generic facility, which allows to allocate
unit numbers within a specified range.
@@ -135,6 +144,41 @@ Free a previously allocated unit number.
This function may require allocating memory, and thus it can sleep.
There is no pre-locked variant.
.El
+.Sh ITERATOR INTERFACE
+The
+.Nm unr
+facility provides an interface to iterate over all allocated units
+for the given
+.Dv unrhdr .
+Iterators are identified by an opaque handle.
+More than one iterators can operate simultaneously; the iterator position
+data is recorded only in the iterator handle.
+.Pp
+Consumers must ensure that the unit allocator is not modified between
+calls to the iterator functions.
+In particular, the internal allocator mutex cannot provide consistency,
+because it is acquired and dropped inside the
+.Fn next_iter_unr
+function.
+If the allocator was modified, it is safe to free the iterator with
+.Fn free_iter_unr
+method nevertheless.
+.Bl -tag -width indent
+.It Fn create_iter_unr uh
+Create an iterator.
+Return the handle that should be passed to other iterator functions.
+.It Fn next_iter_unr handle
+Return the value of the next unit.
+Units are returned in ascending order.
+A return value of
+.Li \-1
+indicates the end of iteration, in which
+case
+.Li \-1
+is returned for all future calls.
+.It Fn free_iter_unr handle
+Free the iterator, handle is no longer valid.
+.El
.Sh CODE REFERENCES
The above functions are implemented in
.Pa sys/kern/subr_unit.c .