]> git.ozlabs.org Git - petitboot/commitdiff
Add list insert routines
authorGeoff Levand <geoffrey.levand@am.sony.com>
Sat, 7 Feb 2009 18:35:53 +0000 (18:35 +0000)
committerJeremy Kerr <jk@ozlabs.org>
Sat, 21 Feb 2009 00:06:22 +0000 (11:06 +1100)
Add new list insertion routines list_insert_before(), list_insert_after(),
and list_add_tail().  Also, change list_add() to use list_insert_after().

Signed-off-by: Geoff Levand <geoffrey.levand@am.sony.com>
Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
lib/list/list.c
lib/list/list.h

index d9bc5324f25a645223a496de0292188e02da7cb1..b781bc65ac4fb5d04e11979f8a4dfe10cb25690e 100644 (file)
@@ -7,13 +7,20 @@ void list_init(struct list *list)
        list->head.prev = &list->head;
 }
 
        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)
 }
 
 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;
 }
        item->next->prev = item->prev;
        item->prev->next = item->next;
 }
-
index 3858cf6f1a287bed6cfdac209f16de4dc3f4c286..fe2c1d39358e8614cbc7cd8deed23df6e7d50a8d 100644 (file)
@@ -31,9 +31,17 @@ struct list {
             pos = list_entry(pos->member.next, typeof(*pos), member))
 
 void list_init(struct list *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);
 
 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 */
 #endif /* _LIST_H */