~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/include/linux/rculist_nulls.h

Version: ~ [ linux-5.2 ] ~ [ linux-5.1.16 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.57 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.132 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.184 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.184 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.19.8 ] ~ [ linux-3.18.140 ] ~ [ linux-3.17.8 ] ~ [ linux-3.16.69 ] ~ [ linux-3.15.10 ] ~ [ linux-3.14.79 ] ~ [ linux-3.13.11 ] ~ [ linux-3.12.74 ] ~ [ linux-3.11.10 ] ~ [ linux-3.10.108 ] ~ [ linux-3.9.11 ] ~ [ linux-3.8.13 ] ~ [ linux-3.7.10 ] ~ [ linux-3.6.11 ] ~ [ linux-3.5.7 ] ~ [ linux-3.4.113 ] ~ [ linux-3.3.8 ] ~ [ linux-3.2.102 ] ~ [ linux-3.1.10 ] ~ [ linux-3.0.101 ] ~ [ linux-2.6.39.4 ] ~ [ linux-2.6.38.8 ] ~ [ linux-2.6.37.6 ] ~ [ linux-2.6.36.4 ] ~ [ linux-2.6.35.14 ] ~ [ linux-2.6.34.15 ] ~ [ linux-2.6.33.20 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /* SPDX-License-Identifier: GPL-2.0 */
  2 #ifndef _LINUX_RCULIST_NULLS_H
  3 #define _LINUX_RCULIST_NULLS_H
  4 
  5 #ifdef __KERNEL__
  6 
  7 /*
  8  * RCU-protected list version
  9  */
 10 #include <linux/list_nulls.h>
 11 #include <linux/rcupdate.h>
 12 
 13 /**
 14  * hlist_nulls_del_init_rcu - deletes entry from hash list with re-initialization
 15  * @n: the element to delete from the hash list.
 16  *
 17  * Note: hlist_nulls_unhashed() on the node return true after this. It is
 18  * useful for RCU based read lockfree traversal if the writer side
 19  * must know if the list entry is still hashed or already unhashed.
 20  *
 21  * In particular, it means that we can not poison the forward pointers
 22  * that may still be used for walking the hash list and we can only
 23  * zero the pprev pointer so list_unhashed() will return true after
 24  * this.
 25  *
 26  * The caller must take whatever precautions are necessary (such as
 27  * holding appropriate locks) to avoid racing with another
 28  * list-mutation primitive, such as hlist_nulls_add_head_rcu() or
 29  * hlist_nulls_del_rcu(), running on this same list.  However, it is
 30  * perfectly legal to run concurrently with the _rcu list-traversal
 31  * primitives, such as hlist_nulls_for_each_entry_rcu().
 32  */
 33 static inline void hlist_nulls_del_init_rcu(struct hlist_nulls_node *n)
 34 {
 35         if (!hlist_nulls_unhashed(n)) {
 36                 __hlist_nulls_del(n);
 37                 n->pprev = NULL;
 38         }
 39 }
 40 
 41 #define hlist_nulls_first_rcu(head) \
 42         (*((struct hlist_nulls_node __rcu __force **)&(head)->first))
 43 
 44 #define hlist_nulls_next_rcu(node) \
 45         (*((struct hlist_nulls_node __rcu __force **)&(node)->next))
 46 
 47 /**
 48  * hlist_nulls_del_rcu - deletes entry from hash list without re-initialization
 49  * @n: the element to delete from the hash list.
 50  *
 51  * Note: hlist_nulls_unhashed() on entry does not return true after this,
 52  * the entry is in an undefined state. It is useful for RCU based
 53  * lockfree traversal.
 54  *
 55  * In particular, it means that we can not poison the forward
 56  * pointers that may still be used for walking the hash list.
 57  *
 58  * The caller must take whatever precautions are necessary
 59  * (such as holding appropriate locks) to avoid racing
 60  * with another list-mutation primitive, such as hlist_nulls_add_head_rcu()
 61  * or hlist_nulls_del_rcu(), running on this same list.
 62  * However, it is perfectly legal to run concurrently with
 63  * the _rcu list-traversal primitives, such as
 64  * hlist_nulls_for_each_entry().
 65  */
 66 static inline void hlist_nulls_del_rcu(struct hlist_nulls_node *n)
 67 {
 68         __hlist_nulls_del(n);
 69         n->pprev = LIST_POISON2;
 70 }
 71 
 72 /**
 73  * hlist_nulls_add_head_rcu
 74  * @n: the element to add to the hash list.
 75  * @h: the list to add to.
 76  *
 77  * Description:
 78  * Adds the specified element to the specified hlist_nulls,
 79  * while permitting racing traversals.
 80  *
 81  * The caller must take whatever precautions are necessary
 82  * (such as holding appropriate locks) to avoid racing
 83  * with another list-mutation primitive, such as hlist_nulls_add_head_rcu()
 84  * or hlist_nulls_del_rcu(), running on this same list.
 85  * However, it is perfectly legal to run concurrently with
 86  * the _rcu list-traversal primitives, such as
 87  * hlist_nulls_for_each_entry_rcu(), used to prevent memory-consistency
 88  * problems on Alpha CPUs.  Regardless of the type of CPU, the
 89  * list-traversal primitive must be guarded by rcu_read_lock().
 90  */
 91 static inline void hlist_nulls_add_head_rcu(struct hlist_nulls_node *n,
 92                                         struct hlist_nulls_head *h)
 93 {
 94         struct hlist_nulls_node *first = h->first;
 95 
 96         n->next = first;
 97         n->pprev = &h->first;
 98         rcu_assign_pointer(hlist_nulls_first_rcu(h), n);
 99         if (!is_a_nulls(first))
100                 first->pprev = &n->next;
101 }
102 
103 /**
104  * hlist_nulls_for_each_entry_rcu - iterate over rcu list of given type
105  * @tpos:       the type * to use as a loop cursor.
106  * @pos:        the &struct hlist_nulls_node to use as a loop cursor.
107  * @head:       the head for your list.
108  * @member:     the name of the hlist_nulls_node within the struct.
109  *
110  * The barrier() is needed to make sure compiler doesn't cache first element [1],
111  * as this loop can be restarted [2]
112  * [1] Documentation/atomic_ops.txt around line 114
113  * [2] Documentation/RCU/rculist_nulls.txt around line 146
114  */
115 #define hlist_nulls_for_each_entry_rcu(tpos, pos, head, member)                 \
116         for (({barrier();}),                                                    \
117              pos = rcu_dereference_raw(hlist_nulls_first_rcu(head));            \
118                 (!is_a_nulls(pos)) &&                                           \
119                 ({ tpos = hlist_nulls_entry(pos, typeof(*tpos), member); 1; }); \
120                 pos = rcu_dereference_raw(hlist_nulls_next_rcu(pos)))
121 
122 /**
123  * hlist_nulls_for_each_entry_safe -
124  *   iterate over list of given type safe against removal of list entry
125  * @tpos:       the type * to use as a loop cursor.
126  * @pos:        the &struct hlist_nulls_node to use as a loop cursor.
127  * @head:       the head for your list.
128  * @member:     the name of the hlist_nulls_node within the struct.
129  */
130 #define hlist_nulls_for_each_entry_safe(tpos, pos, head, member)                \
131         for (({barrier();}),                                                    \
132              pos = rcu_dereference_raw(hlist_nulls_first_rcu(head));            \
133                 (!is_a_nulls(pos)) &&                                           \
134                 ({ tpos = hlist_nulls_entry(pos, typeof(*tpos), member);        \
135                    pos = rcu_dereference_raw(hlist_nulls_next_rcu(pos)); 1; });)
136 #endif
137 #endif
138 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp