2 * Copyright (c) 2015 François Tigeot
3 * Copyright (c) 2016-2020 Mellanox Technologies, Ltd.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice unmodified, this list of conditions, and the following
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 #ifndef _LINUX_RCULIST_H_
31 #define _LINUX_RCULIST_H_
33 #include <linux/list.h>
34 #include <linux/rcupdate.h>
36 #define list_entry_rcu(ptr, type, member) \
37 container_of(READ_ONCE(ptr), type, member)
39 #define list_next_rcu(head) (*((struct list_head **)(&(head)->next)))
40 #define list_prev_rcu(head) (*((struct list_head **)(&(head)->prev)))
42 #define list_for_each_entry_rcu(pos, head, member) \
43 for (pos = list_entry_rcu((head)->next, typeof(*(pos)), member); \
44 &(pos)->member != (head); \
45 pos = list_entry_rcu((pos)->member.next, typeof(*(pos)), member))
48 linux_list_add_rcu(struct list_head *new, struct list_head *prev,
49 struct list_head *next)
53 rcu_assign_pointer(list_next_rcu(prev), new);
58 list_add_rcu(struct list_head *new, struct list_head *head)
60 linux_list_add_rcu(new, head, head->next);
64 list_add_tail_rcu(struct list_head *new, struct list_head *head)
66 linux_list_add_rcu(new, head->prev, head);
70 __list_del_rcu(struct list_head *prev, struct list_head *next)
73 rcu_assign_pointer(list_next_rcu(prev), next);
77 __list_del_entry_rcu(struct list_head *entry)
79 __list_del_rcu(entry->prev, entry->next);
83 list_del_rcu(struct list_head *entry)
85 __list_del_rcu(entry->prev, entry->next);
88 #define hlist_first_rcu(head) (*((struct hlist_node **)(&(head)->first)))
89 #define hlist_next_rcu(node) (*((struct hlist_node **)(&(node)->next)))
90 #define hlist_pprev_rcu(node) (*((struct hlist_node **)((node)->pprev)))
93 hlist_add_behind_rcu(struct hlist_node *n, struct hlist_node *prev)
96 n->pprev = &prev->next;
97 rcu_assign_pointer(hlist_next_rcu(prev), n);
99 n->next->pprev = &n->next;
102 #define hlist_for_each_entry_rcu(pos, head, member) \
103 for (pos = hlist_entry_safe (rcu_dereference_raw(hlist_first_rcu(head)),\
104 typeof(*(pos)), member); \
106 pos = hlist_entry_safe(rcu_dereference_raw(hlist_next_rcu( \
107 &(pos)->member)), typeof(*(pos)), member))
110 hlist_del_rcu(struct hlist_node *n)
112 struct hlist_node *next = n->next;
113 struct hlist_node **pprev = n->pprev;
115 WRITE_ONCE(*pprev, next);
121 hlist_add_head_rcu(struct hlist_node *n, struct hlist_head *h)
123 struct hlist_node *first = h->first;
126 n->pprev = &h->first;
127 rcu_assign_pointer(hlist_first_rcu(h), n);
129 first->pprev = &n->next;
133 hlist_del_init_rcu(struct hlist_node *n)
135 if (!hlist_unhashed(n)) {
141 #endif /* _LINUX_RCULIST_H_ */