[FFmpeg-cvslog] [ffmpeg] branch master updated. 1f4fed5cc3 w32pthreads: add support for setting thread name

ffmpeg-git at ffmpeg.org ffmpeg-git at ffmpeg.org
Fri Aug 15 22:54:50 EEST 2025


The branch, master has been updated
       via  1f4fed5cc3be0737305e342f753c42716d6bf432 (commit)
      from  5ff2500514a0224b7c2822d3b4e950b473f5bcff (commit)


- Log -----------------------------------------------------------------
commit 1f4fed5cc3be0737305e342f753c42716d6bf432
Author:     Kacper Michajłow <kasper93 at gmail.com>
AuthorDate: Tue Mar 4 13:49:56 2025 +0100
Commit:     James Almer <jamrial at gmail.com>
CommitDate: Fri Aug 15 19:54:01 2025 +0000

    w32pthreads: add support for setting thread name
    
    Signed-off-by: Kacper Michajłow <kasper93 at gmail.com>

diff --git a/compat/w32pthreads.h b/compat/w32pthreads.h
index fd6428e29f..6f2734b470 100644
--- a/compat/w32pthreads.h
+++ b/compat/w32pthreads.h
@@ -44,6 +44,7 @@
 #include "libavutil/internal.h"
 #include "libavutil/mem.h"
 #include "libavutil/time.h"
+#include "libavutil/wchar_filename.h"
 
 typedef struct pthread_t {
     void *handle;
@@ -209,4 +210,38 @@ static inline int pthread_setcancelstate(int state, int *oldstate)
     return 0;
 }
 
+static inline int win32_thread_setname(const char *name)
+{
+#if !HAVE_UWP
+    typedef HRESULT (WINAPI *SetThreadDescriptionFn)(HANDLE, PCWSTR);
+
+    // Although SetThreadDescription lives in kernel32.dll, on Windows Server 2016,
+    // Windows 10 LTSB 2016 and Windows 10 version 1607, it was only available in
+    // kernelbase.dll. So, load it from there for maximum coverage.
+    HMODULE kernelbase = GetModuleHandleW(L"kernelbase.dll");
+    if (!kernelbase)
+        return AVERROR(ENOSYS);
+
+    SetThreadDescriptionFn pSetThreadDescription =
+        (SetThreadDescriptionFn)GetProcAddress(kernelbase, "SetThreadDescription");
+    if (!pSetThreadDescription)
+        return AVERROR(ENOSYS);
+
+    wchar_t *wname;
+    if (utf8towchar(name, &wname) < 0)
+        return AVERROR(ENOMEM);
+
+    HRESULT hr = pSetThreadDescription(GetCurrentThread(), wname);
+    av_free(wname);
+    return SUCCEEDED(hr) ? 0 : AVERROR(EINVAL);
+#else
+    // UWP is not supported because we cannot use LoadLibrary/GetProcAddress to
+    // detect the availability of the SetThreadDescription API. There is a small
+    // gap in Windows builds 1507-1607 where it was not available. UWP allows
+    // querying the availability of APIs with QueryOptionalDelayLoadedAPI, but it
+    // requires /DELAYLOAD:kernel32.dll during linking, and we cannot enforce that.
+    return AVERROR(ENOSYS);
+#endif
+}
+
 #endif /* COMPAT_W32PTHREADS_H */
diff --git a/libavutil/thread.h b/libavutil/thread.h
index 2c00c7cc35..184e2d8c5f 100644
--- a/libavutil/thread.h
+++ b/libavutil/thread.h
@@ -229,6 +229,8 @@ static inline int ff_thread_setname(const char *name)
 #endif
 #elif HAVE_PTHREAD_SET_NAME_NP
     pthread_set_name_np(pthread_self(), name);
+#elif HAVE_W32THREADS
+    ret = win32_thread_setname(name);
 #else
     ret = AVERROR(ENOSYS);
 #endif

-----------------------------------------------------------------------

Summary of changes:
 compat/w32pthreads.h | 35 +++++++++++++++++++++++++++++++++++
 libavutil/thread.h   |  2 ++
 2 files changed, 37 insertions(+)


hooks/post-receive
-- 



More information about the ffmpeg-cvslog mailing list