From b88cb42428f14fabdaf947150c00d65891820635 Mon Sep 17 00:00:00 2001 From: Ingo Molnar Date: Mon, 12 Dec 2005 00:37:11 -0800 Subject: [PATCH] add hlist_replace_rcu() Add list_replace_rcu: replace old entry by new one. Signed-off-by: Paul E. McKenney Signed-off-by: Ingo Molnar Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- include/linux/list.h | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) (limited to 'include/linux/list.h') diff --git a/include/linux/list.h b/include/linux/list.h index fbfca73355a..8e338828453 100644 --- a/include/linux/list.h +++ b/include/linux/list.h @@ -202,12 +202,15 @@ static inline void list_del_rcu(struct list_head *entry) * * 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){ +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; + old->prev = LIST_POISON2; } /** @@ -578,6 +581,27 @@ static inline void hlist_del_init(struct hlist_node *n) } } +/* + * hlist_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 hlist_replace_rcu(struct hlist_node *old, + struct hlist_node *new) +{ + struct hlist_node *next = old->next; + + new->next = next; + new->pprev = old->pprev; + smp_wmb(); + if (next) + new->next->pprev = &new->next; + *new->pprev = new; + old->pprev = LIST_POISON2; +} + static inline void hlist_add_head(struct hlist_node *n, struct hlist_head *h) { struct hlist_node *first = h->first; -- cgit v1.2.3-70-g09d2 From 0ad42352c01788e41a33336577fdd270d8de55bb Mon Sep 17 00:00:00 2001 From: David Howells Date: Mon, 9 Jan 2006 20:51:31 -0800 Subject: [PATCH] Add list_for_each_entry_safe_reverse() Add list_for_each_entry_safe_reverse() to linux/list.h This is needed by unmerged cachefs and be an as-yet-unreviewed device_shutdown() fix. Signed-off-by: David Howells Cc: Patrick Mochel Cc: Greg KH Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- include/linux/list.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'include/linux/list.h') diff --git a/include/linux/list.h b/include/linux/list.h index 8e338828453..945daa1f13d 100644 --- a/include/linux/list.h +++ b/include/linux/list.h @@ -435,6 +435,20 @@ static inline void list_splice_init(struct list_head *list, &pos->member != (head); \ pos = n, n = list_entry(n->member.next, typeof(*n), member)) +/** + * list_for_each_entry_safe_reverse - iterate backwards over list of given type safe against + * removal of list entry + * @pos: the type * to use as a loop counter. + * @n: another type * to use as temporary storage + * @head: the head for your list. + * @member: the name of the list_struct within the struct. + */ +#define list_for_each_entry_safe_reverse(pos, n, head, member) \ + for (pos = list_entry((head)->prev, typeof(*pos), member), \ + n = list_entry(pos->member.prev, typeof(*pos), member); \ + &pos->member != (head); \ + pos = n, n = list_entry(n->member.prev, typeof(*n), member)) + /** * list_for_each_rcu - iterate over an rcu-protected list * @pos: the &struct list_head to use as a loop counter. -- cgit v1.2.3-70-g09d2