* sentinel head node, "prev" links not maintained.
*/
_INLINE_ struct list_head *merge(int (*cmp)(struct list_head *a,
- struct list_head *b),
+ struct list_head *b,
+ void *data),
+ void *data,
struct list_head *a, struct list_head *b)
{
struct list_head head, *tail = &head;
while (a && b) {
/* if equal, take 'a' -- important for sort stability */
- if ((*cmp)(a, b) <= 0) {
+ if ((*cmp)(a, b, data) <= 0) {
tail->next = a;
a = a->next;
} else {
* throughout.
*/
_INLINE_ void merge_and_restore_back_links(int (*cmp)(struct list_head *a,
- struct list_head *b),
+ struct list_head *b,
+ void *data),
+ void *data,
struct list_head *head,
struct list_head *a, struct list_head *b)
{
while (a && b) {
/* if equal, take 'a' -- important for sort stability */
- if ((*cmp)(a, b) <= 0) {
+ if ((*cmp)(a, b, data) <= 0) {
tail->next = a;
a->prev = tail;
a = a->next;
* element comparison is needed, so the client's cmp()
* routine can invoke cond_resched() periodically.
*/
- (*cmp)(tail->next, tail->next);
+ (*cmp)(tail->next, tail->next, data);
tail->next->prev = tail;
tail = tail->next;
*/
_INLINE_ void list_sort(struct list_head *head,
int (*cmp)(struct list_head *a,
- struct list_head *b))
+ struct list_head *b,
+ void *data),
+ void *data)
{
struct list_head *part[MAX_LIST_LENGTH_BITS+1]; /* sorted partial lists
-- last slot is a sentinel */
cur->next = NULL;
for (lev = 0; part[lev]; lev++) {
- cur = merge(cmp, part[lev], cur);
+ cur = merge(cmp, data, part[lev], cur);
part[lev] = NULL;
}
if (lev > max_lev) {
for (lev = 0; lev < max_lev; lev++)
if (part[lev])
- list = merge(cmp, part[lev], list);
+ list = merge(cmp, data, part[lev], list);
- merge_and_restore_back_links(cmp, head, part[max_lev], list);
+ merge_and_restore_back_links(cmp, data, head, part[max_lev], list);
}
#undef _INLINE_