summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsascha <sascha@nomad.localdomain>2007-10-19 12:43:00 +0200
committersascha <sascha@nomad.localdomain>2007-10-19 12:43:00 +0200
commitf1020bd2d508c150fea98ab79b8ca7458ccb4a13 (patch)
tree293820fef75b8b38ef56a6eb8d7222b98e357f45
parent8a46c1102f7772a5c890da6512988d09c33686a2 (diff)
downloadbarebox-f1020bd2d508c150fea98ab79b8ca7458ccb4a13.tar.gz
barebox-f1020bd2d508c150fea98ab79b8ca7458ccb4a13.tar.xz
add list_add_sort to list implementation
-rw-r--r--include/list.h24
1 files changed, 24 insertions, 0 deletions
diff --git a/include/list.h b/include/list.h
index 17d3576ed2..1e8bc51b9d 100644
--- a/include/list.h
+++ b/include/list.h
@@ -429,6 +429,30 @@ static inline void list_splice_init(struct list_head *list,
&pos->member != (head); \
pos = n, n = list_entry(n->member.prev, typeof(*n), member))
+/**
+ * list_add_sort - add a new entry to a sorted list
+ * @new: new entry to be added
+ * @head: list head to add it in
+ * @compare: Compare function to compare two list entries
+ *
+ * Insert a new entry before the specified head.
+ * This is useful for implementing queues.
+ */
+static inline void list_add_sort(struct list_head *new, struct list_head *head,
+ int (*compare)(struct list_head *a, struct list_head *b))
+{
+ struct list_head *pos, *insert = head;
+
+ list_for_each(pos, head) {
+ if (compare(pos, new) < 0)
+ continue;
+ insert = pos;
+ break;
+ }
+
+ list_add_tail(new, insert);
+}
+
/*
* Double linked lists with a single pointer list head.
* Mostly useful for hash tables where the two pointer list head is