Mesa (main): util/list.h: add a function to move an item in a list

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Fri Apr 22 17:20:44 UTC 2022


Module: Mesa
Branch: main
Commit: 0ae787f2232d5ad6285bedba04a29f8a13a54e5e
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=0ae787f2232d5ad6285bedba04a29f8a13a54e5e

Author: Dylan Baker <dylan.c.baker at intel.com>
Date:   Wed Mar 16 11:19:49 2022 -0700

util/list.h: add a function to move an item in a list

This allows for a 1:1 replacement of simple_list move_to_head (though
I've tried to make this function more generally useful.

Reviewed-by: Roland Scheidegger <sroland at vmware.com>
Reviewed-by: Jason Ekstrand <jason.ekstrand at collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/15418>

---

 src/util/list.h | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/src/util/list.h b/src/util/list.h
index 383073b122a..5ef49e4e955 100644
--- a/src/util/list.h
+++ b/src/util/list.h
@@ -179,6 +179,19 @@ static inline void list_validate(const struct list_head *list)
       assert(node->next->prev == node && node->prev->next == node);
 }
 
+/**
+ * Move an item from one place in a list to another
+ *
+ * The item can be in this list, or in another.
+ *
+ * @param item The item to move
+ * @param loc  The element to put the item in front of
+ */
+static inline void list_move_to(struct list_head *item, struct list_head *loc) {
+   list_del(item);
+   list_add(item, loc);
+}
+
 #define LIST_ENTRY(__type, __item, __field)   \
     ((__type *)(((char *)(__item)) - offsetof(__type, __field)))
 



More information about the mesa-commit mailing list