[Midnightbsd-cvs] src [8372] trunk: implement LIST_PREV
laffer1 at midnightbsd.org
laffer1 at midnightbsd.org
Sun Sep 18 15:05:19 EDT 2016
Revision: 8372
http://svnweb.midnightbsd.org/src/?rev=8372
Author: laffer1
Date: 2016-09-18 15:05:19 -0400 (Sun, 18 Sep 2016)
Log Message:
-----------
implement LIST_PREV
Modified Paths:
--------------
trunk/share/man/man3/Makefile
trunk/share/man/man3/queue.3
trunk/sys/sys/param.h
trunk/sys/sys/queue.h
Modified: trunk/share/man/man3/Makefile
===================================================================
--- trunk/share/man/man3/Makefile 2016-09-18 19:04:32 UTC (rev 8371)
+++ trunk/share/man/man3/Makefile 2016-09-18 19:05:19 UTC (rev 8372)
@@ -52,6 +52,7 @@
queue.3 LIST_INSERT_BEFORE.3 \
queue.3 LIST_INSERT_HEAD.3 \
queue.3 LIST_NEXT.3 \
+ queue.3 LIST_PREV.3 \
queue.3 LIST_REMOVE.3 \
queue.3 LIST_SWAP.3 \
queue.3 SLIST_EMPTY.3 \
Modified: trunk/share/man/man3/queue.3
===================================================================
--- trunk/share/man/man3/queue.3 2016-09-18 19:04:32 UTC (rev 8371)
+++ trunk/share/man/man3/queue.3 2016-09-18 19:05:19 UTC (rev 8372)
@@ -32,7 +32,7 @@
.\" @(#)queue.3 8.2 (Berkeley) 1/24/94
.\" $MidnightBSD$
.\"
-.Dd May 13, 2011
+.Dd Sep 12, 2012
.Dt QUEUE 3
.Os
.Sh NAME
@@ -81,6 +81,7 @@
.Nm LIST_INSERT_BEFORE ,
.Nm LIST_INSERT_HEAD ,
.Nm LIST_NEXT ,
+.Nm LIST_PREV ,
.Nm LIST_REMOVE ,
.Nm LIST_SWAP ,
.Nm TAILQ_CONCAT ,
@@ -155,6 +156,7 @@
.Fn LIST_INSERT_BEFORE "TYPE *listelm" "TYPE *elm" "LIST_ENTRY NAME"
.Fn LIST_INSERT_HEAD "LIST_HEAD *head" "TYPE *elm" "LIST_ENTRY NAME"
.Fn LIST_NEXT "TYPE *elm" "LIST_ENTRY NAME"
+.Fn LIST_PREV "TYPE *elm" "LIST_HEAD *head" "TYPE" "LIST_ENTRY NAME"
.Fn LIST_REMOVE "TYPE *elm" "LIST_ENTRY NAME"
.Fn LIST_SWAP "LIST_HEAD *head1" "LIST_HEAD *head2" "TYPE" "LIST_ENTRY NAME"
.\"
@@ -248,8 +250,18 @@
twice that of the singly-linked data-structures.
.El
.Pp
-Linked lists are the simplest of the doubly linked data structures and support
-only the above functionality over singly-linked lists.
+Linked lists are the simplest of the doubly linked data structures.
+They add the following functionality over the above:
+.Bl -enum -compact -offset indent
+.It
+They may be traversed backwards.
+.El
+However:
+.Bl -enum -compact -offset indent
+.It
+To traverse backwards, an entry to begin the traversal and the list in
+which it is contained must be specified.
+.El
.Pp
Tail queues add the following functionality:
.Bl -enum -compact -offset indent
@@ -763,6 +775,14 @@
returns the next element in the list, or NULL if this is the last.
.Pp
The macro
+.Nm LIST_PREV
+returns the previous element in the list, or NULL if this is the first.
+List
+.Fa head
+must contain element
+.Fa elm .
+.Pp
+The macro
.Nm LIST_REMOVE
removes the element
.Fa elm
Modified: trunk/sys/sys/param.h
===================================================================
--- trunk/sys/sys/param.h 2016-09-18 19:04:32 UTC (rev 8371)
+++ trunk/sys/sys/param.h 2016-09-18 19:05:19 UTC (rev 8372)
@@ -324,8 +324,7 @@
((db) << (PAGE_SHIFT - DEV_BSHIFT))
/*
- * Given the pointer x to the member m of the struct s, return
- * a pointer to the containing structure.
+ * Old spelling of __containerof().
*/
#define member2struct(s, m, x) \
((struct s *)(void *)((char *)(x) - offsetof(struct s, m)))
Modified: trunk/sys/sys/queue.h
===================================================================
--- trunk/sys/sys/queue.h 2016-09-18 19:04:32 UTC (rev 8371)
+++ trunk/sys/sys/queue.h 2016-09-18 19:05:19 UTC (rev 8372)
@@ -65,7 +65,7 @@
* so that an arbitrary element can be removed without a need to
* traverse the list. New elements can be added to the list before
* or after an existing element or at the head of the list. A list
- * may only be traversed in the forward direction.
+ * may be traversed in either direction.
*
* A tail queue is headed by a pair of pointers, one to the head of the
* list and the other to the tail of the list. The elements are doubly
@@ -85,7 +85,7 @@
* _EMPTY + + + +
* _FIRST + + + +
* _NEXT + + + +
- * _PREV - - - +
+ * _PREV - + - +
* _LAST - - + +
* _FOREACH + + + +
* _FOREACH_SAFE + + + +
@@ -287,10 +287,8 @@
} while (0)
#define STAILQ_LAST(head, type, field) \
- (STAILQ_EMPTY((head)) ? \
- NULL : \
- ((struct type *)(void *) \
- ((char *)((head)->stqh_last) - __offsetof(struct type, field))))
+ (STAILQ_EMPTY((head)) ? NULL : \
+ __containerof((head)->stqh_last, struct type, field.stqe_next))
#define STAILQ_NEXT(elm, field) ((elm)->field.stqe_next)
@@ -425,6 +423,10 @@
#define LIST_NEXT(elm, field) ((elm)->field.le_next)
+#define LIST_PREV(elm, head, type, field) \
+ ((elm)->field.le_prev == &LIST_FIRST((head)) ? NULL : \
+ __containerof((elm)->field.le_prev, struct type, field.le_next))
+
#define LIST_REMOVE(elm, field) do { \
QMD_SAVELINK(oldnext, (elm)->field.le_next); \
QMD_SAVELINK(oldprev, (elm)->field.le_prev); \
More information about the Midnightbsd-cvs
mailing list