From 6fb19a8904560a27309e2995932d4826c0562130 Mon Sep 17 00:00:00 2001 From: "Henrik \"Henke37\" Andersson" Date: Wed, 29 Apr 2020 21:39:44 +0200 Subject: [PATCH] libobs: Use SetThreadDescription if possible It's the better way to declare thread names, but you need Windows 10, version 1607 to use it. --- libobs/util/threading-windows.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/libobs/util/threading-windows.c b/libobs/util/threading-windows.c index f4a9659c1..72b5792a2 100644 --- a/libobs/util/threading-windows.c +++ b/libobs/util/threading-windows.c @@ -16,6 +16,7 @@ #include "bmem.h" #include "threading.h" +#include "util/platform.h" #define WIN32_LEAN_AND_MEAN #include @@ -192,4 +193,21 @@ void os_set_thread_name(const char *name) #endif } #endif + + typedef HRESULT(WINAPI * set_thread_description_t)(HANDLE thread, + PCWSTR desc); + + HMODULE k32 = LoadLibraryW(L"Kernel32.dll"); + set_thread_description_t std = NULL; + std = (set_thread_description_t)GetProcAddress(k32, + "SetThreadDescription"); + if (std) { + wchar_t *wname; + os_utf8_to_wcs_ptr(name, 0, &wname); + + std(GetCurrentThread(), wname); + + bfree(wname); + } + FreeLibrary(k32); }