diff options
author | Jeff Darcy <jdarcy@redhat.com> | 2014-04-22 15:37:09 +0000 |
---|---|---|
committer | Jeff Darcy <jdarcy@redhat.com> | 2014-04-22 15:37:09 +0000 |
commit | a827c5eab32a43ade5551259ea56a6a1af7e861b (patch) | |
tree | e6707df68f72baa8645210ba931272285116ad85 /libglusterfs/src/list.h | |
parent | 46d333783a968ab39e0beade9c7a1eec8035f8b1 (diff) | |
parent | 99bfc2a2a1689da1e173cb2f8ef54d2b09ef3a5d (diff) |
Merge branch 'upstream'
Conflicts:
glusterfs.spec.in
xlators/mgmt/glusterd/src/Makefile.am
xlators/mgmt/glusterd/src/glusterd-utils.c
xlators/mgmt/glusterd/src/glusterd.h
Change-Id: I27bdcf42b003cfc42d6ad981bd2bf8180176806d
Diffstat (limited to 'libglusterfs/src/list.h')
-rw-r--r-- | libglusterfs/src/list.h | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/libglusterfs/src/list.h b/libglusterfs/src/list.h index c9a2fb070..3bb991fac 100644 --- a/libglusterfs/src/list.h +++ b/libglusterfs/src/list.h @@ -45,19 +45,29 @@ list_add_tail (struct list_head *new, struct list_head *head) } +/* This function will insert the element to the list in a order. + Order will be based on the compare function provided as a input. + If element to be inserted in ascending order compare should return: + 0: if both the arguments are equal + >0: if first argument is greater than second argument + <0: if first argument is less than second argument */ static inline void list_add_order (struct list_head *new, struct list_head *head, int (*compare)(struct list_head *, struct list_head *)) { - struct list_head *pos = head->next; + struct list_head *pos = head->prev; while ( pos != head ) { - if (compare(new, pos) <= 0) + if (compare(new, pos) >= 0) break; - pos = pos->next; + + /* Iterate the list in the reverse order. This will have + better efficiency if the elements are inserted in the + ascending order */ + pos = pos->prev; } - list_add_tail(new, pos); + list_add (new, pos); } static inline void |