Changeset View
Changeset View
Standalone View
Standalone View
sys/dev/drm2/drm_linux_list_sort.c
Show All 32 Lines | |||||
__FBSDID("$FreeBSD$"); | __FBSDID("$FreeBSD$"); | ||||
struct drm_list_sort_thunk { | struct drm_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 int | static int | ||||
drm_le_cmp(void *priv, const void *d1, const void *d2) | drm_le_cmp(const void *d1, const void *d2, void *priv) | ||||
{ | { | ||||
struct list_head *le1, *le2; | struct list_head *le1, *le2; | ||||
struct drm_list_sort_thunk *thunk; | struct drm_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 14 Lines | drm_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_TEMP, M_WAITOK); | ar = malloc(sizeof(struct list_head *) * count, M_TEMP, 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, drm_le_cmp); | qsort_r(ar, count, sizeof(struct list_head *), drm_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_TEMP); | free(ar, M_TEMP); | ||||
} | } |