summaryrefslogtreecommitdiffstats
path: root/include/linux/rculist.h
diff options
context:
space:
mode:
authorTom Herbert <tom@herbertland.com>2016-03-07 14:11:00 -0800
committerDavid S. Miller <davem@davemloft.net>2016-03-09 16:36:13 -0500
commitff3c44e675054533403909ecb76e78c1d4efbd26 (patch)
tree5700cd86c182eaa9172de44d3151439e4ff745ed /include/linux/rculist.h
parent26e9093110fb9ceb10093e4914b129b58d49a425 (diff)
downloadlinux-ff3c44e675054533403909ecb76e78c1d4efbd26.tar.gz
linux-ff3c44e675054533403909ecb76e78c1d4efbd26.tar.bz2
linux-ff3c44e675054533403909ecb76e78c1d4efbd26.zip
rcu: Add list_next_or_null_rcu
This is a convenience function that returns the next entry in an RCU list or NULL if at the end of the list. Signed-off-by: Tom Herbert <tom@herbertland.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'include/linux/rculist.h')
-rw-r--r--include/linux/rculist.h21
1 files changed, 21 insertions, 0 deletions
diff --git a/include/linux/rculist.h b/include/linux/rculist.h
index 14ec1652daf4..17d4f849c65e 100644
--- a/include/linux/rculist.h
+++ b/include/linux/rculist.h
@@ -319,6 +319,27 @@ static inline void list_splice_tail_init_rcu(struct list_head *list,
})
/**
+ * list_next_or_null_rcu - get the first element from a list
+ * @head: the head for the list.
+ * @ptr: the list head to take the next element from.
+ * @type: the type of the struct this is embedded in.
+ * @member: the name of the list_head within the struct.
+ *
+ * Note that if the ptr is at the end of the list, NULL is returned.
+ *
+ * This primitive may safely run concurrently with the _rcu list-mutation
+ * primitives such as list_add_rcu() as long as it's guarded by rcu_read_lock().
+ */
+#define list_next_or_null_rcu(head, ptr, type, member) \
+({ \
+ struct list_head *__head = (head); \
+ struct list_head *__ptr = (ptr); \
+ struct list_head *__next = READ_ONCE(__ptr->next); \
+ likely(__next != __head) ? list_entry_rcu(__next, type, \
+ member) : NULL; \
+})
+
+/**
* list_for_each_entry_rcu - iterate over rcu list of given type
* @pos: the type * to use as a loop cursor.
* @head: the head for your list.