On Thu, Sep 25, 2025 at 10:44:25AM +0100, Daniel P. Berrangé wrote:
> This will be used to include the thread name in error reports
> in a later patch. It returns a const string stored in a thread
> local to avoid memory allocation when it is called repeatedly
> in a single thread. The thread name should be set at the very
> start of the thread execution, which is the case when using
> qemu_thread_create.
>
> Signed-off-by: Daniel P. Berrangé <[email protected]>
> ---
> include/qemu/thread.h | 1 +
> meson.build | 21 +++++++++++++++++
> util/qemu-thread-posix.c | 33 ++++++++++++++++++++++++++-
> util/qemu-thread-win32.c | 49 ++++++++++++++++++++++++++++++++++++----
> 4 files changed, 99 insertions(+), 5 deletions(-)
>
> +++ b/util/qemu-thread-posix.c
> +const char *qemu_thread_get_name(void)
> +# endif
> + if (rv != 0) {
> + strlcpy(namebuf, "unnamed", G_N_ELEMENTS(namebuf));
Should this be g_strlcpy() instead of strlcpy(), for consistency with
the Windows half of the patch, and since g_strlcpy() is much more
frequent in the QEMU codebase?
> +++ b/util/qemu-thread-win32.c
> @@ -38,14 +41,17 @@ static bool load_set_thread_description(void)
> SetThreadDescriptionFunc =
> (pSetThreadDescription)GetProcAddress(kernel32_module,
>
> "SetThreadDescription");
> - if (!SetThreadDescriptionFunc) {
> + GetThreadDescriptionFunc =
> + (pGetThreadDescription)GetProcAddress(kernel32_module,
> +
> "GetThreadDescription");
> + if (!SetThreadDescriptionFunc || !GetThreadDescriptionFunc) {
> FreeLibrary(kernel32_module);
> }
> }
> g_once_init_leave(&_init_once, 1);
> }
>
> - return !!SetThreadDescriptionFunc;
> + return !!(SetThreadDescriptionFunc && GetThreadDescriptionFunc);
Pre-patch, the !! was necessary for converting a pointer to a bool.
But && also converts to a bool, and "!!(bool)" is redundant compared
to just "bool".
But overall, the patch makes sense.
--
Eric Blake, Principal Software Engineer
Red Hat, Inc.
Virtualization: qemu.org | libguestfs.org