X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=include%2Flinux%2Flist.h;h=94bed0f27d338c3fed4f7be77086f015076e917b;hb=c7b5ebbddf7bcd3651947760f423e3783bbe6573;hp=33b863bcb7b9a017a7d1e8f2e870dc6318f31662;hpb=9bf4aaab3e101692164d49b7ca357651eb691cb6;p=linux-2.6.git diff --git a/include/linux/list.h b/include/linux/list.h index 33b863bcb..94bed0f27 100644 --- a/include/linux/list.h +++ b/include/linux/list.h @@ -195,6 +195,21 @@ static inline void list_del_rcu(struct list_head *entry) entry->prev = LIST_POISON2; } +/* + * list_replace_rcu - replace old entry by new one + * @old : the element to be replaced + * @new : the new element to insert + * + * The old entry will be replaced with the new entry atomically. + */ +static inline void list_replace_rcu(struct list_head *old, struct list_head *new){ + new->next = old->next; + new->prev = old->prev; + smp_wmb(); + new->next->prev = new; + new->prev->next = new; +} + /** * list_del_init - deletes entry from list and reinitialize it. * @entry: the element to delete from the list. @@ -420,11 +435,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 +454,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 +470,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 +487,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 +593,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 +640,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 +709,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"