diff options
author | David Gwynne <dlg@cvs.openbsd.org> | 2015-11-21 00:32:47 +0000 |
---|---|---|
committer | David Gwynne <dlg@cvs.openbsd.org> | 2015-11-21 00:32:47 +0000 |
commit | 9f7e052a7fca5c9ece1df332904e2e3695a0d889 (patch) | |
tree | 7183d3d5f6241132c63da183735ebf481d208620 | |
parent | 0fa2d7a2b33773a35ccd3372f54eb80dba5a30b2 (diff) |
provide MBUF_LIST_FIRST and MBUF_LIST_NEXT for iterating over an mbuf_list.
MBUF_LIST_FOREACH is then rewritten on top of those.
this makes it easier to get at the head of a list too, which may make
the hfsc ifq backend nicer.
based on a discussion with kenjiro cho
ok mpi@
-rw-r--r-- | share/man/man9/Makefile | 5 | ||||
-rw-r--r-- | share/man/man9/ml_init.9 | 29 | ||||
-rw-r--r-- | sys/sys/mbuf.h | 11 |
3 files changed, 38 insertions, 7 deletions
diff --git a/share/man/man9/Makefile b/share/man/man9/Makefile index aae5f49d13c..d3039569269 100644 --- a/share/man/man9/Makefile +++ b/share/man/man9/Makefile @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile,v 1.257 2015/11/20 19:05:02 deraadt Exp $ +# $OpenBSD: Makefile,v 1.258 2015/11/21 00:32:46 dlg Exp $ # $NetBSD: Makefile,v 1.4 1996/01/09 03:23:01 thorpej Exp $ # Makefile for section 9 (kernel function and variable) manual pages. @@ -273,7 +273,8 @@ MLINKS+=ml_init.9 ml_enqueue.9 ml_init.9 ml_dequeue.9 ml_init.9 ml_requeue.9 \ ml_init.9 ml_enlist.9 ml_init.9 ml_dechain.9 \ ml_init.9 ml_filter.9 ml_init.9 ml_len.9 ml_init.9 ml_empty.9 \ ml_init.9 ml_purge.9 \ - ml_init.9 MBUF_LIST_INITIALIZER.9 ml_init.9 MBUF_LIST_FOREACH.9 + ml_init.9 MBUF_LIST_INITIALIZER.9 ml_init.9 MBUF_LIST_FIRST.9 \ + ml_init.9 MBUF_LIST_NEXT.9 ml_init.9 MBUF_LIST_FOREACH.9 MLINKS+=mountroothook_establish.9 mountroothook_disestablish.9 MLINKS+=mutex.9 mtx_init.9 mutex.9 mtx_enter.9 mutex.9 mtx_leave.9 \ mutex.9 MUTEX_ASSERT_LOCKED.9 mutex.9 MUTEX_ASSERT_UNLOCKED.9 \ diff --git a/share/man/man9/ml_init.9 b/share/man/man9/ml_init.9 index 6f42f8f618d..6f843aeedd9 100644 --- a/share/man/man9/ml_init.9 +++ b/share/man/man9/ml_init.9 @@ -1,4 +1,4 @@ -.\" $OpenBSD: ml_init.9,v 1.8 2015/11/02 09:21:48 dlg Exp $ +.\" $OpenBSD: ml_init.9,v 1.9 2015/11/21 00:32:46 dlg Exp $ .\" .\" Copyright (c) 2015 David Gwynne <dlg@openbsd.org> .\" @@ -14,7 +14,7 @@ .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. .\" -.Dd $Mdocdate: November 2 2015 $ +.Dd $Mdocdate: November 21 2015 $ .Dt ML_INIT 9 .Os .Sh NAME @@ -27,6 +27,8 @@ .Nm ml_len , .Nm ml_empty , .Nm MBUF_LIST_INITIALIZER , +.Nm MBUF_LIST_FIRST , +.Nm MBUF_LIST_NEXT , .Nm MBUF_LIST_FOREACH .Nd mbuf list API .Sh SYNOPSIS @@ -57,6 +59,10 @@ .Fn ml_purge "struct mbuf_list *ml" .Ft struct mbuf_list .Fn MBUF_LIST_INITIALIZER +.Ft struct mbuf * +.Fn MBUF_LIST_FIRST "struct mbuf_list *ml" +.Ft struct mbuf * +.Fn MBUF_LIST_NEXT "struct mbuf *m" .Fn MBUF_LIST_FOREACH "struct mbuf_list *ml" "VARNAME" .Sh DESCRIPTION The mbuf list API provides implementations of data structures and operations @@ -138,6 +144,13 @@ mbuf list is empty. Free all the mbufs on the .Fa ml mbuf list. +.It Fn MBUF_LIST_FIRST "struct mbuf_list *ml" +Access the first mbuf in the +.Fa ml +mbuf list for traversal. +.It Fn MBUF_LIST_NEXT "struct mbuf *m" +Access the next mbuf in the mbuf list after +.Fa m . .It Fn MBUF_LIST_FOREACH "struct mbuf_list *ml" "VARNAME" A convenience macro that can be used to iterate over the contents of the .Fa ml @@ -158,6 +171,8 @@ Note that it is unsafe to modify the list while iterating over it. .Fn ml_empty , .Fn ml_purge , .Fn MBUF_LIST_INITIALIZER , +.Fn MBUF_LIST_FIRST , +.Fn MBUF_LIST_NEXT , and .Fn MBUF_LIST_FOREACH can be called during autoconf, from process context, or from interrupt context. @@ -190,5 +205,15 @@ return a non-zero value if the list is empty, otherwise 0. .Pp .Fn ml_purge returns the number of mbufs that were freed. +.Pp +.Fn MBUF_LIST_FIRST +returns the first mbuf in the mbuf list, or +.Dv NULL +if the list is empty. +.Pp +.Fn MBUF_LIST_NEXT +returns the next mbuf in the mbuf list, or +.Dv NULL +if the end of the list has been reached. .Sh SEE ALSO .Xr mbuf 9 diff --git a/sys/sys/mbuf.h b/sys/sys/mbuf.h index 81bcdddacc5..2d1f5271d8f 100644 --- a/sys/sys/mbuf.h +++ b/sys/sys/mbuf.h @@ -1,4 +1,4 @@ -/* $OpenBSD: mbuf.h,v 1.203 2015/11/20 03:35:23 dlg Exp $ */ +/* $OpenBSD: mbuf.h,v 1.204 2015/11/21 00:32:46 dlg Exp $ */ /* $NetBSD: mbuf.h,v 1.19 1996/02/09 18:25:14 christos Exp $ */ /* @@ -504,8 +504,13 @@ unsigned int ml_purge(struct mbuf_list *); #define ml_len(_ml) ((_ml)->ml_len) #define ml_empty(_ml) ((_ml)->ml_len == 0) -#define MBUF_LIST_FOREACH(_ml, _m) \ - for ((_m) = (_ml)->ml_head; (_m) != NULL; (_m) = (_m)->m_nextpkt) +#define MBUF_LIST_FIRST(_ml) ((_ml)->ml_head) +#define MBUF_LIST_NEXT(_m) ((_m)->m_nextpkt) + +#define MBUF_LIST_FOREACH(_ml, _m) \ + for ((_m) = MBUF_LIST_FIRST(_ml); \ + (_m) != NULL; \ + (_m) = MBUF_LIST_NEXT(_m)) /* * mbuf queues |