lib/sort: Move swap, cmp and cmp_r function types for wider use
The function types for swap, cmp and cmp_r functions are already being in use by modules. Move them to types.h that everybody in kernel will be able to use generic types instead of custom ones. This adds more sense to the comment in bsearch() later on. Link: http://lkml.kernel.org/r/20191007135656.37734-1-andriy.shevchenko@linux.intel.com Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
This commit is contained in:
parent
b43e78f65b
commit
52ae533b8a
|
@ -5,12 +5,12 @@
|
||||||
#include <linux/types.h>
|
#include <linux/types.h>
|
||||||
|
|
||||||
void sort_r(void *base, size_t num, size_t size,
|
void sort_r(void *base, size_t num, size_t size,
|
||||||
int (*cmp)(const void *, const void *, const void *),
|
cmp_r_func_t cmp_func,
|
||||||
void (*swap)(void *, void *, int),
|
swap_func_t swap_func,
|
||||||
const void *priv);
|
const void *priv);
|
||||||
|
|
||||||
void sort(void *base, size_t num, size_t size,
|
void sort(void *base, size_t num, size_t size,
|
||||||
int (*cmp)(const void *, const void *),
|
cmp_func_t cmp_func,
|
||||||
void (*swap)(void *, void *, int));
|
swap_func_t swap_func);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -225,5 +225,10 @@ struct callback_head {
|
||||||
typedef void (*rcu_callback_t)(struct rcu_head *head);
|
typedef void (*rcu_callback_t)(struct rcu_head *head);
|
||||||
typedef void (*call_rcu_func_t)(struct rcu_head *head, rcu_callback_t func);
|
typedef void (*call_rcu_func_t)(struct rcu_head *head, rcu_callback_t func);
|
||||||
|
|
||||||
|
typedef void (*swap_func_t)(void *a, void *b, int size);
|
||||||
|
|
||||||
|
typedef int (*cmp_r_func_t)(const void *a, const void *b, const void *priv);
|
||||||
|
typedef int (*cmp_func_t)(const void *a, const void *b);
|
||||||
|
|
||||||
#endif /* __ASSEMBLY__ */
|
#endif /* __ASSEMBLY__ */
|
||||||
#endif /* _LINUX_TYPES_H */
|
#endif /* _LINUX_TYPES_H */
|
||||||
|
|
15
lib/sort.c
15
lib/sort.c
|
@ -117,8 +117,6 @@ static void swap_bytes(void *a, void *b, size_t n)
|
||||||
} while (n);
|
} while (n);
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef void (*swap_func_t)(void *a, void *b, int size);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The values are arbitrary as long as they can't be confused with
|
* The values are arbitrary as long as they can't be confused with
|
||||||
* a pointer, but small integers make for the smallest compare
|
* a pointer, but small integers make for the smallest compare
|
||||||
|
@ -144,12 +142,9 @@ static void do_swap(void *a, void *b, size_t size, swap_func_t swap_func)
|
||||||
swap_func(a, b, (int)size);
|
swap_func(a, b, (int)size);
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef int (*cmp_func_t)(const void *, const void *);
|
|
||||||
typedef int (*cmp_r_func_t)(const void *, const void *, const void *);
|
|
||||||
#define _CMP_WRAPPER ((cmp_r_func_t)0L)
|
#define _CMP_WRAPPER ((cmp_r_func_t)0L)
|
||||||
|
|
||||||
static int do_cmp(const void *a, const void *b,
|
static int do_cmp(const void *a, const void *b, cmp_r_func_t cmp, const void *priv)
|
||||||
cmp_r_func_t cmp, const void *priv)
|
|
||||||
{
|
{
|
||||||
if (cmp == _CMP_WRAPPER)
|
if (cmp == _CMP_WRAPPER)
|
||||||
return ((cmp_func_t)(priv))(a, b);
|
return ((cmp_func_t)(priv))(a, b);
|
||||||
|
@ -202,8 +197,8 @@ static size_t parent(size_t i, unsigned int lsbit, size_t size)
|
||||||
* it less suitable for kernel use.
|
* it less suitable for kernel use.
|
||||||
*/
|
*/
|
||||||
void sort_r(void *base, size_t num, size_t size,
|
void sort_r(void *base, size_t num, size_t size,
|
||||||
int (*cmp_func)(const void *, const void *, const void *),
|
cmp_r_func_t cmp_func,
|
||||||
void (*swap_func)(void *, void *, int size),
|
swap_func_t swap_func,
|
||||||
const void *priv)
|
const void *priv)
|
||||||
{
|
{
|
||||||
/* pre-scale counters for performance */
|
/* pre-scale counters for performance */
|
||||||
|
@ -269,8 +264,8 @@ void sort_r(void *base, size_t num, size_t size,
|
||||||
EXPORT_SYMBOL(sort_r);
|
EXPORT_SYMBOL(sort_r);
|
||||||
|
|
||||||
void sort(void *base, size_t num, size_t size,
|
void sort(void *base, size_t num, size_t size,
|
||||||
int (*cmp_func)(const void *, const void *),
|
cmp_func_t cmp_func,
|
||||||
void (*swap_func)(void *, void *, int size))
|
swap_func_t swap_func)
|
||||||
{
|
{
|
||||||
return sort_r(base, num, size, _CMP_WRAPPER, swap_func, cmp_func);
|
return sort_r(base, num, size, _CMP_WRAPPER, swap_func, cmp_func);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue