From c6b0b69c55658bb0c88433444dc288f91b0cb357 Mon Sep 17 00:00:00 2001 From: "Bjoern B. Brandenburg" Date: Thu, 23 Aug 2007 17:54:07 -0400 Subject: Add generic list insert --- include/linux/list.h | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'include/linux') diff --git a/include/linux/list.h b/include/linux/list.h index 611059d633..e7d758c5fa 100644 --- a/include/linux/list.h +++ b/include/linux/list.h @@ -898,6 +898,36 @@ static inline void hlist_add_after_rcu(struct hlist_node *prev, ({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \ pos = pos->next) + +typedef int (*list_cmp_t)(struct list_head*, struct list_head*); + +static inline unsigned int list_insert(struct list_head* new, + struct list_head* head, + list_cmp_t is_less) +{ + struct list_head *pos; + unsigned int passed = 0; + + BUG_ON(!new); + + /* find a spot where the new entry is less than the next */ + list_for_each(pos, head) { + if (unlikely(is_less(new, pos))) { + /* pos is not less than new, thus insert here */ + __list_add(new, pos->prev, pos); + goto out; + } + passed++; + } + /* if we get to this point either the list is empty or every entry + * queued element is less than new. + * Let's add new to the end. */ + list_add_tail(new, head); + out: + return passed; +} + + #else #warning "don't include kernel headers in userspace" #endif /* __KERNEL__ */ -- cgit v1.2.2