Browse Source

[PATCH] add hlist_replace_rcu()

Add list_replace_rcu: replace old entry by new one.

Signed-off-by: Paul E. McKenney <paulmck@us.ibm.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Ingo Molnar 19 years ago
parent
commit
b88cb42428
1 changed files with 25 additions and 1 deletions
  1. 25 1
      include/linux/list.h

+ 25 - 1
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.
  * 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->next = old->next;
 	new->prev = old->prev;
 	new->prev = old->prev;
 	smp_wmb();
 	smp_wmb();
 	new->next->prev = new;
 	new->next->prev = new;
 	new->prev->next = 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)
 static inline void hlist_add_head(struct hlist_node *n, struct hlist_head *h)
 {
 {
 	struct hlist_node *first = h->first;
 	struct hlist_node *first = h->first;