From 5c312079417908381ffca44d18150b6a990c4f0b Mon Sep 17 00:00:00 2001 From: "Dr. David Alan Gilbert" Date: Wed, 12 Mar 2014 11:48:18 +0000 Subject: Detect pthread_setname_np at configure time Warn if no way of setting thread name is available. Signed-off-by: Dr. David Alan Gilbert Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- util/qemu-thread-posix.c | 21 ++++++++++++++++++--- util/qemu-thread-win32.c | 2 ++ 2 files changed, 20 insertions(+), 3 deletions(-) (limited to 'util') diff --git a/util/qemu-thread-posix.c b/util/qemu-thread-posix.c index 960d7f5..d05a649 100644 --- a/util/qemu-thread-posix.c +++ b/util/qemu-thread-posix.c @@ -32,6 +32,13 @@ static bool name_threads; void qemu_thread_naming(bool enable) { name_threads = enable; + +#ifndef CONFIG_THREAD_SETNAME_BYTHREAD + /* This is a debugging option, not fatal */ + if (enable) { + fprintf(stderr, "qemu: thread naming not supported on this host\n"); + } +#endif } static void error_exit(int err, const char *msg) @@ -394,6 +401,16 @@ void qemu_event_wait(QemuEvent *ev) } } +/* Attempt to set the threads name; note that this is for debug, so + * we're not going to fail if we can't set it. + */ +static void qemu_thread_set_name(QemuThread *thread, const char *name) +{ +#ifdef CONFIG_PTHREAD_SETNAME_NP + pthread_setname_np(thread->thread, name); +#endif +} + void qemu_thread_create(QemuThread *thread, const char *name, void *(*start_routine)(void*), void *arg, int mode) @@ -420,11 +437,9 @@ void qemu_thread_create(QemuThread *thread, const char *name, if (err) error_exit(err, __func__); -#if defined(__GLIBC__) && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 12)) if (name_threads) { - pthread_setname_np(thread->thread, name); + qemu_thread_set_name(thread, name); } -#endif pthread_sigmask(SIG_SETMASK, &oldset, NULL); diff --git a/util/qemu-thread-win32.c b/util/qemu-thread-win32.c index b9c957b..c405c9b 100644 --- a/util/qemu-thread-win32.c +++ b/util/qemu-thread-win32.c @@ -22,6 +22,8 @@ void qemu_thread_naming(bool enable) { /* But note we don't actually name them on Windows yet */ name_threads = enable; + + fprintf(stderr, "qemu: thread naming not supported on this host\n"); } static void error_exit(int err, const char *msg) -- cgit v1.1