Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/external/bsd/drm2/include/linux Hokey Linux sort routine...



details:   https://anonhg.NetBSD.org/src/rev/a8880d27e98d
branches:  trunk
changeset: 1027859:a8880d27e98d
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Sun Dec 19 00:58:50 2021 +0000

description:
Hokey Linux sort routine. Doesn't support swap argument.

diffstat:

 sys/external/bsd/drm2/include/linux/sort.h |  22 +++++++++++++++++++++-
 1 files changed, 21 insertions(+), 1 deletions(-)

diffs (34 lines):

diff -r 8f7fe71b0d43 -r a8880d27e98d sys/external/bsd/drm2/include/linux/sort.h
--- a/sys/external/bsd/drm2/include/linux/sort.h        Sun Dec 19 00:58:42 2021 +0000
+++ b/sys/external/bsd/drm2/include/linux/sort.h        Sun Dec 19 00:58:50 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: sort.h,v 1.1 2021/12/19 00:28:12 riastradh Exp $       */
+/*     $NetBSD: sort.h,v 1.2 2021/12/19 00:58:50 riastradh Exp $       */
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -32,4 +32,24 @@
 #ifndef        _LINUX_SORT_H_
 #define        _LINUX_SORT_H_
 
+#include <sys/kmem.h>
+
+#include <lib/libkern/libkern.h>
+
+static inline void
+sort(void *array, size_t nelem, size_t elemsize,
+    int (*cmp)(const void *, const void *),
+    void (*swap)(void *, void *, int))
+{
+       void *tmp;
+
+       KASSERT(swap == NULL);  /* XXX */
+       KASSERT(elemsize != 0);
+       KASSERT(nelem <= SIZE_MAX/elemsize);
+
+       tmp = kmem_alloc(nelem*elemsize, KM_SLEEP);
+       kheapsort(array, nelem, elemsize, cmp, tmp);
+       kmem_free(tmp, nelem*elemsize);
+}
+
 #endif /* _LINUX_SORT_H_ */



Home | Main Index | Thread Index | Old Index