summaryrefslogtreecommitdiff
path: root/kern/list.h
diff options
context:
space:
mode:
authorRichard Braun <rbraun@sceen.net>2017-07-24 23:55:52 +0200
committerRichard Braun <rbraun@sceen.net>2017-07-24 23:55:52 +0200
commit58144c76b6e8600999f8cd401c7a89ae8f55f947 (patch)
tree35eaece6ab80dddb86f1894a06598fd77445d038 /kern/list.h
parentf504f743a969a82012a8c60283fe130c1dc5d74f (diff)
kern/list: update from upstream
Diffstat (limited to 'kern/list.h')
-rw-r--r--kern/list.h129
1 files changed, 70 insertions, 59 deletions
diff --git a/kern/list.h b/kern/list.h
index c31b71a..eeb2934 100644
--- a/kern/list.h
+++ b/kern/list.h
@@ -15,7 +15,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*
- * Simple doubly-linked list.
+ * Doubly-linked list.
*/
#ifndef _KERN_LIST_H
@@ -58,7 +58,7 @@ list_init(struct list *list)
/*
* Initialize a list node.
*
- * An entry is in no lists when its node members point to NULL.
+ * A node is in no list when its node members point to NULL.
*/
static inline void
list_node_init(struct list *node)
@@ -68,7 +68,7 @@ list_node_init(struct list *node)
}
/*
- * Return true if node is in no lists.
+ * Return true if node is in no list.
*/
static inline bool
list_node_unlinked(const struct list *node)
@@ -77,12 +77,6 @@ list_node_unlinked(const struct list *node)
}
/*
- * Macro that evaluates to the address of the structure containing the
- * given node based on the given type and member.
- */
-#define list_entry(node, type, member) structof(node, type, member)
-
-/*
* Return the first node of a list.
*/
static inline struct list *
@@ -119,31 +113,7 @@ list_prev(const struct list *node)
}
/*
- * Get the first entry of a list.
- */
-#define list_first_entry(list, type, member) \
- list_entry(list_first(list), type, member)
-
-/*
- * Get the last entry of a list.
- */
-#define list_last_entry(list, type, member) \
- list_entry(list_last(list), type, member)
-
-/*
- * Get the entry next to the given entry.
- */
-#define list_next_entry(entry, member) \
- list_entry(list_next(&(entry)->member), typeof(*(entry)), member)
-
-/*
- * Get the entry previous to the given entry.
- */
-#define list_prev_entry(entry, member) \
- list_entry(list_prev(&(entry)->member), typeof(*(entry)), member)
-
-/*
- * Return true if node is after the last or before the first node of the list.
+ * Return true if node is invalid and denotes one of the ends of the list.
*/
static inline bool
list_end(const struct list *list, const struct list *node)
@@ -305,6 +275,36 @@ list_remove(struct list *node)
}
/*
+ * Macro that evaluates to the address of the structure containing the
+ * given node based on the given type and member.
+ */
+#define list_entry(node, type, member) structof(node, type, member)
+
+/*
+ * Get the first entry of a list.
+ */
+#define list_first_entry(list, type, member) \
+ list_entry(list_first(list), type, member)
+
+/*
+ * Get the last entry of a list.
+ */
+#define list_last_entry(list, type, member) \
+ list_entry(list_last(list), type, member)
+
+/*
+ * Get the entry next to the given entry.
+ */
+#define list_next_entry(entry, member) \
+ list_entry(list_next(&(entry)->member), typeof(*(entry)), member)
+
+/*
+ * Get the entry previous to the given entry.
+ */
+#define list_prev_entry(entry, member) \
+ list_entry(list_prev(&(entry)->member), typeof(*(entry)), member)
+
+/*
* Forge a loop to process all nodes of a list.
*
* The node must not be altered during the loop.
@@ -382,13 +382,6 @@ for (entry = list_last_entry(list, typeof(*entry), member), \
*/
/*
- * Macro that evaluates to the address of the structure containing the
- * given node based on the given type and member.
- */
-#define list_llsync_entry(node, type, member) \
- structof(llsync_read_ptr(node), type, member)
-
-/*
* Return the first node of a list.
*/
static inline struct list *
@@ -407,24 +400,6 @@ list_llsync_next(const struct list *node)
}
/*
- * Get the first entry of a list.
- *
- * Unlike list_entry(), this macro may evaluate to NULL, because the node
- * pointer can only be read once, preventing the combination of lockless
- * list_empty()/list_first_entry() variants.
- *
- * Return NULL if the list is empty.
- */
-#define list_llsync_first_entry(list, type, member) \
-MACRO_BEGIN \
- struct list *___list = (list); \
- struct list *___first = llsync_read_ptr(___list->next); \
- list_end(___list, ___first) \
- ? NULL \
- : list_entry(___first, type, member); \
-MACRO_END
-
-/*
* Add a node between two nodes.
*
* This function is private.
@@ -487,6 +462,42 @@ list_llsync_remove(struct list *node)
}
/*
+ * Macro that evaluates to the address of the structure containing the
+ * given node based on the given type and member.
+ */
+#define list_llsync_entry(node, type, member) \
+ structof(llsync_read_ptr(node), type, member)
+
+/*
+ * Get the first entry of a list.
+ *
+ * Unlike list_first_entry(), this macro may evaluate to NULL, because
+ * the node pointer can only be read once, preventing the combination
+ * of lockless list_empty()/list_first_entry() variants.
+ */
+#define list_llsync_first_entry(list, type, member) \
+MACRO_BEGIN \
+ struct list *___list; \
+ struct list *___first; \
+ \
+ ___list = (list); \
+ ___first = list_llsync_first(___list); \
+ list_end(___list, ___first) \
+ ? NULL \
+ : list_entry(___first, type, member); \
+MACRO_END
+
+/*
+ * Get the entry next to the given entry.
+ *
+ * Unlike list_next_entry(), this macro may evaluate to NULL, because
+ * the node pointer can only be read once, preventing the combination
+ * of lockless list_empty()/list_next_entry() variants.
+ */
+#define list_llsync_next_entry(entry, member) \
+ list_llsync_first_entry(&entry->member, typeof(*entry), member)
+
+/*
* Forge a loop to process all nodes of a list.
*
* The node must not be altered during the loop.