summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAidan MacDonald <amachronic@protonmail.com>2022-07-31 16:23:55 +0100
committerAidan MacDonald <amachronic@protonmail.com>2022-10-16 16:10:24 +0100
commit5e864ecde98fbb2f115f75a3c5c13fa871f4d3f9 (patch)
treeeeb419c5c0117b31c0e770985c387ad9c82fd303
parentee9679993bddead1341bf7f36a97ef982f25a396 (diff)
downloadrockbox-5e864ecde9.tar.gz
rockbox-5e864ecde9.zip
linked list: add lld_insert_prev/next()
Change-Id: I55ff061ccc0e6e2dad3125a8150c082c163db329
-rw-r--r--firmware/common/linked_list.c32
-rw-r--r--firmware/include/linked_list.h4
2 files changed, 36 insertions, 0 deletions
diff --git a/firmware/common/linked_list.c b/firmware/common/linked_list.c
index 7697a052ca..30e4e6079a 100644
--- a/firmware/common/linked_list.c
+++ b/firmware/common/linked_list.c
@@ -133,6 +133,38 @@ void ll_remove(struct ll_head *list, struct ll_node *node)
/** (L)inked (L)ist (D)ouble **/
+void lld_insert_next(struct lld_head *list, struct lld_node *node,
+ struct lld_node *newnode)
+{
+ struct lld_node **nodep = node != NULL ? &node->next : &list->head;
+ struct lld_node *next = *nodep;
+
+ newnode->next = next;
+ newnode->prev = node;
+ *nodep = newnode;
+
+ if (next == NULL)
+ list->tail = newnode;
+ else
+ next->prev = newnode;
+}
+
+void lld_insert_prev(struct lld_head *list, struct lld_node *node,
+ struct lld_node *newnode)
+{
+ struct lld_node **nodep = node != NULL ? &node->prev : &list->tail;
+ struct lld_node *prev = *nodep;
+
+ newnode->next = node;
+ newnode->prev = prev;
+ *nodep = newnode;
+
+ if (prev == NULL)
+ list->head = newnode;
+ else
+ prev->next = newnode;
+}
+
/**
* Adds a node to a doubly-linked list using "insert first"
*/
diff --git a/firmware/include/linked_list.h b/firmware/include/linked_list.h
index b307977f2e..1e077be22a 100644
--- a/firmware/include/linked_list.h
+++ b/firmware/include/linked_list.h
@@ -103,6 +103,10 @@ static inline void lld_init(struct lld_head *list)
the routines and maintains the non-circularity */
}
+void lld_insert_next(struct lld_head *list, struct lld_node *node,
+ struct lld_node *newnode);
+void lld_insert_prev(struct lld_head *list, struct lld_node *node,
+ struct lld_node *newnode);
void lld_insert_first(struct lld_head *list, struct lld_node *node);
void lld_insert_last(struct lld_head *list, struct lld_node *node);
void lld_remove(struct lld_head *list, struct lld_node *node);