]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/compat/linuxkpi/common/include/linux/rculist.h
Import mandoc 1.14.4
[FreeBSD/FreeBSD.git] / sys / compat / linuxkpi / common / include / linux / rculist.h
1 /*-
2  * Copyright (c) 2015 François Tigeot
3  * Copyright (c) 2016-2017 Mellanox Technologies, Ltd.
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice unmodified, this list of conditions, and the following
11  *    disclaimer.
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.
15  *
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.
26  *
27  * $FreeBSD$
28  */
29
30 #ifndef _LINUX_RCULIST_H_
31 #define _LINUX_RCULIST_H_
32
33 #include <linux/list.h>
34 #include <linux/rcupdate.h>
35
36 #define hlist_first_rcu(head)   (*((struct hlist_node **)(&(head)->first)))
37 #define hlist_next_rcu(node)    (*((struct hlist_node **)(&(node)->next)))
38 #define hlist_pprev_rcu(node)   (*((struct hlist_node **)((node)->pprev)))
39
40 static inline void
41 hlist_add_behind_rcu(struct hlist_node *n, struct hlist_node *prev)
42 {
43         n->next = prev->next;
44         n->pprev = &prev->next;
45         rcu_assign_pointer(hlist_next_rcu(prev), n);
46         if (n->next)
47                 n->next->pprev = &n->next;
48 }
49
50 #define hlist_for_each_entry_rcu(pos, head, member)     \
51         hlist_for_each_entry(pos, head, member)
52
53 static inline void
54 hlist_del_rcu(struct hlist_node *n)
55 {
56         struct hlist_node *next = n->next;
57         struct hlist_node **pprev = n->pprev;
58
59         WRITE_ONCE(*pprev, next);
60         if (next)
61                 next->pprev = pprev;
62 }
63
64 static inline void
65 hlist_add_head_rcu(struct hlist_node *n, struct hlist_head *h)
66 {
67         struct hlist_node *first = h->first;
68
69         n->next = first;
70         n->pprev = &h->first;
71         rcu_assign_pointer(hlist_first_rcu(h), n);
72         if (first)
73                 first->pprev = &n->next;
74 }
75
76 static inline void
77 hlist_del_init_rcu(struct hlist_node *n)
78 {
79         if (!hlist_unhashed(n)) {
80                 hlist_del_rcu(n);
81                 n->pprev = NULL;
82         }
83 }
84
85 #endif                                  /* _LINUX_RCULIST_H_ */