aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux
diff options
context:
space:
mode:
authorBjoern B. Brandenburg <bbb@cs.unc.edu>2007-08-23 17:54:07 -0400
committerBjoern B. Brandenburg <bbb@cs.unc.edu>2007-08-23 17:54:07 -0400
commitc6b0b69c55658bb0c88433444dc288f91b0cb357 (patch)
tree72f1b49ad134484d6c51118f0f13fc8434482097 /include/linux
parentb87ba375bbae9c8bec71bd09322dfe42fac2b34f (diff)
Add generic list insert
Diffstat (limited to 'include/linux')
-rw-r--r--include/linux/list.h30
1 files changed, 30 insertions, 0 deletions
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,
898 ({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \ 898 ({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \
899 pos = pos->next) 899 pos = pos->next)
900 900
901
902typedef int (*list_cmp_t)(struct list_head*, struct list_head*);
903
904static inline unsigned int list_insert(struct list_head* new,
905 struct list_head* head,
906 list_cmp_t is_less)
907{
908 struct list_head *pos;
909 unsigned int passed = 0;
910
911 BUG_ON(!new);
912
913 /* find a spot where the new entry is less than the next */
914 list_for_each(pos, head) {
915 if (unlikely(is_less(new, pos))) {
916 /* pos is not less than new, thus insert here */
917 __list_add(new, pos->prev, pos);
918 goto out;
919 }
920 passed++;
921 }
922 /* if we get to this point either the list is empty or every entry
923 * queued element is less than new.
924 * Let's add new to the end. */
925 list_add_tail(new, head);
926 out:
927 return passed;
928}
929
930
901#else 931#else
902#warning "don't include kernel headers in userspace" 932#warning "don't include kernel headers in userspace"
903#endif /* __KERNEL__ */ 933#endif /* __KERNEL__ */