summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/linux/list.h27
-rw-r--r--include/linux/rcupdate.h16
2 files changed, 30 insertions, 13 deletions
diff --git a/include/linux/list.h b/include/linux/list.h
index 33b863bcb7b9..4de68939e495 100644
--- a/include/linux/list.h
+++ b/include/linux/list.h
@@ -420,11 +420,11 @@ static inline void list_splice_init(struct list_head *list,
*/
#define list_for_each_rcu(pos, head) \
for (pos = (head)->next, prefetch(pos->next); pos != (head); \
- pos = pos->next, ({ smp_read_barrier_depends(); 0;}), prefetch(pos->next))
+ pos = rcu_dereference(pos->next), prefetch(pos->next))
#define __list_for_each_rcu(pos, head) \
for (pos = (head)->next; pos != (head); \
- pos = pos->next, ({ smp_read_barrier_depends(); 0;}))
+ pos = rcu_dereference(pos->next))
/**
* list_for_each_safe_rcu - iterate over an rcu-protected list safe
@@ -439,7 +439,7 @@ static inline void list_splice_init(struct list_head *list,
*/
#define list_for_each_safe_rcu(pos, n, head) \
for (pos = (head)->next, n = pos->next; pos != (head); \
- pos = n, ({ smp_read_barrier_depends(); 0;}), n = pos->next)
+ pos = rcu_dereference(n), n = pos->next)
/**
* list_for_each_entry_rcu - iterate over rcu list of given type
@@ -455,8 +455,8 @@ static inline void list_splice_init(struct list_head *list,
for (pos = list_entry((head)->next, typeof(*pos), member), \
prefetch(pos->member.next); \
&pos->member != (head); \
- pos = list_entry(pos->member.next, typeof(*pos), member), \
- ({ smp_read_barrier_depends(); 0;}), \
+ pos = rcu_dereference(list_entry(pos->member.next, \
+ typeof(*pos), member)), \
prefetch(pos->member.next))
@@ -472,7 +472,7 @@ static inline void list_splice_init(struct list_head *list,
*/
#define list_for_each_continue_rcu(pos, head) \
for ((pos) = (pos)->next, prefetch((pos)->next); (pos) != (head); \
- (pos) = (pos)->next, ({ smp_read_barrier_depends(); 0;}), prefetch((pos)->next))
+ (pos) = rcu_dereference((pos)->next), prefetch((pos)->next))
/*
* Double linked lists with a single pointer list head.
@@ -578,12 +578,9 @@ static inline void hlist_add_head(struct hlist_node *n, struct hlist_head *h)
* or hlist_del_rcu(), running on this same list.
* However, it is perfectly legal to run concurrently with
* the _rcu list-traversal primitives, such as
- * hlist_for_each_entry(), but only if smp_read_barrier_depends()
- * is used to prevent memory-consistency problems on Alpha CPUs.
- * Regardless of the type of CPU, the list-traversal primitive
- * must be guarded by rcu_read_lock().
- *
- * OK, so why don't we have an hlist_for_each_entry_rcu()???
+ * hlist_for_each_rcu(), used to prevent memory-consistency
+ * problems on Alpha CPUs. Regardless of the type of CPU, the
+ * list-traversal primitive must be guarded by rcu_read_lock().
*/
static inline void hlist_add_head_rcu(struct hlist_node *n,
struct hlist_head *h)
@@ -628,6 +625,10 @@ static inline void hlist_add_after(struct hlist_node *n,
for (pos = (head)->first; pos && ({ n = pos->next; 1; }); \
pos = n)
+#define hlist_for_each_rcu(pos, head) \
+ for ((pos) = (head)->first; pos && ({ prefetch((pos)->next); 1; }); \
+ (pos) = rcu_dereference((pos)->next))
+
/**
* hlist_for_each_entry - iterate over list of given type
* @tpos: the type * to use as a loop counter.
@@ -693,7 +694,7 @@ static inline void hlist_add_after(struct hlist_node *n,
for (pos = (head)->first; \
pos && ({ prefetch(pos->next); 1;}) && \
({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \
- pos = pos->next, ({ smp_read_barrier_depends(); 0; }) )
+ pos = rcu_dereference(pos->next))
#else
#warning "don't include kernel headers in userspace"
diff --git a/include/linux/rcupdate.h b/include/linux/rcupdate.h
index 32a8893a3cdd..b12bdd9d8f6d 100644
--- a/include/linux/rcupdate.h
+++ b/include/linux/rcupdate.h
@@ -222,6 +222,22 @@ static inline int rcu_pending(int cpu)
*/
#define rcu_read_unlock_bh() local_bh_enable()
+/**
+ * rcu_dereference - fetch an RCU-protected pointer in an
+ * RCU read-side critical section. This pointer may later
+ * be safely dereferenced.
+ *
+ * Inserts memory barriers on architectures that require them
+ * (currently only the Alpha), and, more importantly, documents
+ * exactly which pointers are protected by RCU.
+ */
+
+#define rcu_dereference(p) ({ \
+ typeof(p) _________p1 = p; \
+ smp_read_barrier_depends(); \
+ (_________p1); \
+ })
+
extern void rcu_init(void);
extern void rcu_check_callbacks(int cpu, int user);
extern void rcu_restart_cpu(int cpu);