From 8371f981f172426271635adf0e37b2b4aeccbe0e Mon Sep 17 00:00:00 2001 From: Brian Behlendorf Date: Fri, 27 Aug 2010 13:51:25 -0700 Subject: [PATCH] Add list_link_replace() function The list_link_replace() function with swap a new item it to the place of an old item in a list. It is the callers responsibility to ensure all lists involved are locked properly. --- include/sys/list.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/include/sys/list.h b/include/sys/list.h index e30d7b7..303b959 100644 --- a/include/sys/list.h +++ b/include/sys/list.h @@ -203,4 +203,17 @@ spl_list_move_tail(list_t *dst, list_t *src) #define list_move_tail(dst, src) spl_list_move_tail(dst, src) +static inline void +list_link_replace(list_node_t *old_node, list_node_t *new_node) +{ + ASSERT(list_link_active(old_node)); + ASSERT(!list_link_active(new_node)); + + new_node->next = old_node->next; + new_node->prev = old_node->prev; + old_node->prev->next = new_node; + old_node->next->prev = new_node; + list_link_init(old_node); +} + #endif /* SPL_LIST_H */ -- 2.40.0