@samitouri / QOSamiQemu / commits / 8f68a33ad4

audio: make jackaudio use qemu_thread_set_name

This has greater portability than directly call pthread_setname_np, which is only 1 out of 3 possible functions for pthreads that can set the name. The new API requires a trampoline function, since it can only set the name of the current thread. Reviewed-by: Christian Schoenebeck <qemu_oss@crudebyte.com> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>

Daniel P. Berrangé committed Aug 29, 2025 at 16:12 UTC 8f68a33ad46b81accb6200050227e36ec03608f4
1 file changed +23 -5
audio/jackaudio.c
+23 -5
@@ -633,18 +633,36 @@ static void qjack_enable_in(HWVoiceIn *hw, bool enable)
633 ji->c.enabled = enable;
634 }
635
636 -#if !defined(WIN32) && defined(CONFIG_PTHREAD_SETNAME_NP_W_TID)
636 +#if !defined(WIN32)
637 +struct QJackThreadData {
638 + void *(*function)(void *);
639 + void *arg;
640 +};
641 +
642 +static void *qjack_thread_trampoline(void *targ)
643 +{
644 + struct QJackThreadData *data = targ;
645 + void *(*function)(void *) = data->function;
646 + void *arg = data->arg;
647 +
648 + g_free(data);
649 + qemu_thread_set_name("jack-client");
650 +
651 + return function(arg);
652 +}
653 +
654 static int qjack_thread_creator(jack_native_thread_t *thread,
655 const pthread_attr_t *attr, void *(*function)(void *), void *arg)
656 {
640 - int ret = pthread_create(thread, attr, function, arg);
657 + struct QJackThreadData *data = g_new0(struct QJackThreadData, 1);
658 + data->function = function;
659 + data->arg = arg;
660 + int ret = pthread_create(thread, attr, qjack_thread_trampoline, data);
661 if (ret != 0) {
662 + g_free(data);
663 return ret;
664 }
665
645 - /* set the name of the thread */
646 - pthread_setname_np(*thread, "jack-client");
647 -
666 return ret;
667 }
668 #endif