summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/list/list.c18
-rw-r--r--lib/list/list.h14
2 files changed, 23 insertions, 9 deletions
diff --git a/lib/list/list.c b/lib/list/list.c
index d9bc532..b781bc6 100644
--- a/lib/list/list.c
+++ b/lib/list/list.c
@@ -7,13 +7,20 @@ void list_init(struct list *list)
list->head.prev = &list->head;
}
-void list_add(struct list *list, struct list_item *new)
+void list_insert_before(struct list_item *next, struct list_item *new)
{
- new->next = list->head.next;
- new->prev = &list->head;
+ new->next = next;
+ new->prev = next->prev;
+ next->prev->next = new;
+ next->prev = new;
+}
- list->head.next->prev = new;
- list->head.next = new;
+void list_insert_after(struct list_item *prev, struct list_item *new)
+{
+ new->next = prev->next;
+ new->prev = prev;
+ prev->next->prev = new;
+ prev->next = new;
}
void list_remove(struct list_item *item)
@@ -21,4 +28,3 @@ void list_remove(struct list_item *item)
item->next->prev = item->prev;
item->prev->next = item->next;
}
-
diff --git a/lib/list/list.h b/lib/list/list.h
index 3858cf6..fe2c1d3 100644
--- a/lib/list/list.h
+++ b/lib/list/list.h
@@ -31,9 +31,17 @@ struct list {
pos = list_entry(pos->member.next, typeof(*pos), member))
void list_init(struct list *list);
-
-void list_add(struct list *list, struct list_item *item);
-
+void list_insert_before(struct list_item *next, struct list_item *new);
+void list_insert_after(struct list_item *prev, struct list_item *new);
void list_remove(struct list_item *item);
+static inline void list_add(struct list *list, struct list_item *new)
+{
+ list_insert_after(&list->head, new);
+}
+static inline void list_add_tail(struct list *list, struct list_item *new)
+{
+ list_insert_before(&list->head, new);
+}
+
#endif /* _LIST_H */
OpenPOWER on IntegriCloud