Changeset View
Changeset View
Standalone View
Standalone View
sys/compat/linuxkpi/common/src/linux_compat.c
Show First 20 Lines • Show All 2,556 Lines • ▼ Show 20 Lines | |||||
} | } | ||||
struct list_sort_thunk { | struct list_sort_thunk { | ||||
int (*cmp)(void *, struct list_head *, struct list_head *); | int (*cmp)(void *, struct list_head *, struct list_head *); | ||||
void *priv; | void *priv; | ||||
}; | }; | ||||
static inline int | static inline int | ||||
linux_le_cmp(void *priv, const void *d1, const void *d2) | linux_le_cmp(const void *d1, const void *d2, void *priv) | ||||
{ | { | ||||
struct list_head *le1, *le2; | struct list_head *le1, *le2; | ||||
struct list_sort_thunk *thunk; | struct list_sort_thunk *thunk; | ||||
thunk = priv; | thunk = priv; | ||||
le1 = *(__DECONST(struct list_head **, d1)); | le1 = *(__DECONST(struct list_head **, d1)); | ||||
le2 = *(__DECONST(struct list_head **, d2)); | le2 = *(__DECONST(struct list_head **, d2)); | ||||
return ((thunk->cmp)(thunk->priv, le1, le2)); | return ((thunk->cmp)(thunk->priv, le1, le2)); | ||||
Show All 11 Lines | list_sort(void *priv, struct list_head *head, int (*cmp)(void *priv, | ||||
list_for_each(le, head) | list_for_each(le, head) | ||||
count++; | count++; | ||||
ar = malloc(sizeof(struct list_head *) * count, M_KMALLOC, M_WAITOK); | ar = malloc(sizeof(struct list_head *) * count, M_KMALLOC, M_WAITOK); | ||||
i = 0; | i = 0; | ||||
list_for_each(le, head) | list_for_each(le, head) | ||||
ar[i++] = le; | ar[i++] = le; | ||||
thunk.cmp = cmp; | thunk.cmp = cmp; | ||||
thunk.priv = priv; | thunk.priv = priv; | ||||
qsort_r(ar, count, sizeof(struct list_head *), &thunk, linux_le_cmp); | qsort_r(ar, count, sizeof(struct list_head *), linux_le_cmp, &thunk); | ||||
INIT_LIST_HEAD(head); | INIT_LIST_HEAD(head); | ||||
for (i = 0; i < count; i++) | for (i = 0; i < count; i++) | ||||
list_add_tail(ar[i], head); | list_add_tail(ar[i], head); | ||||
free(ar, M_KMALLOC); | free(ar, M_KMALLOC); | ||||
} | } | ||||
#if defined(__i386__) || defined(__amd64__) | #if defined(__i386__) || defined(__amd64__) | ||||
int | int | ||||
▲ Show 20 Lines • Show All 195 Lines • Show Last 20 Lines |