From ef5b272b28acfe7d0c6392e424bfad1c3d1c7275 Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Mon, 26 Jan 2004 15:54:10 +0000 Subject: [PATCH] Stephen Cook : - removed the function-in-function for qsort. replaced with a static function with a static variable. now protected with pthread mutex. --- src/control/hcontrol.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/control/hcontrol.c b/src/control/hcontrol.c index 3779fc80..ed4a11a0 100644 --- a/src/control/hcontrol.c +++ b/src/control/hcontrol.c @@ -48,6 +48,7 @@ to reduce overhead accessing the real controls in kernel drivers. #include #include #include +#include #ifndef DOC_HIDDEN #define __USE_GNU #endif @@ -409,17 +410,26 @@ int snd_hctl_free(snd_hctl_t *hctl) return 0; } +static snd_hctl_t *compare_hctl; +static int hctl_compare(const void *a, const void *b) { + return compare_hctl->compare(*(const snd_hctl_elem_t * const *) a, + *(const snd_hctl_elem_t * const *) b); +} + static void snd_hctl_sort(snd_hctl_t *hctl) { unsigned int k; - int compar(const void *a, const void *b) { - return hctl->compare(*(const snd_hctl_elem_t * const *) a, - *(const snd_hctl_elem_t * const *) b); - } + static pthread_mutex_t sync_lock = PTHREAD_MUTEX_INITIALIZER; + assert(hctl); assert(hctl->compare); INIT_LIST_HEAD(&hctl->elems); - qsort(hctl->pelems, hctl->count, sizeof(*hctl->pelems), compar); + + pthread_mutex_lock(&sync_lock); + compare_hctl = hctl; + qsort(hctl->pelems, hctl->count, sizeof(*hctl->pelems), hctl_compare); + pthread_mutex_unlock(&sync_lock); + for (k = 0; k < hctl->count; k++) list_add_tail(&hctl->pelems[k]->list, &hctl->elems); } -- 2.47.1