Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: "Kacper Michajłow" <kasper93@gmail.com>
To: ffmpeg-devel@ffmpeg.org
Cc: "Kacper Michajłow" <kasper93@gmail.com>
Subject: [FFmpeg-devel] [PATCH] w32pthreads: add support for setting thread name
Date: Tue,  4 Mar 2025 13:52:49 +0100
Message-ID: <20250304125249.1879-1-kasper93@gmail.com> (raw)

Signed-off-by: Kacper Michajłow <kasper93@gmail.com>
---
 compat/w32pthreads.h | 30 ++++++++++++++++++++++++++++++
 libavutil/thread.h   |  2 ++
 2 files changed, 32 insertions(+)

diff --git a/compat/w32pthreads.h b/compat/w32pthreads.h
index fd6428e29f..83b4819205 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,33 @@ static inline int pthread_setcancelstate(int state, int *oldstate)
     return 0;
 }
 
+static inline int win32_thread_setname(const char *name)
+{
+    typedef HRESULT (WINAPI *SetThreadDescriptionFn)(HANDLE, PCWSTR);
+    SetThreadDescriptionFn pSetThreadDescription;
+    HRESULT hr;
+    wchar_t *wname;
+
+#if !HAVE_UWP
+    HMODULE kernel32 = GetModuleHandleW(L"kernel32.dll");
+    if (!kernel32)
+        return ENOSYS;
+    pSetThreadDescription = (SetThreadDescriptionFn)
+        GetProcAddress(kernel32, "SetThreadDescription");
+    if (!pSetThreadDescription)
+        return ENOSYS;
+#else
+    WINBASEAPI HRESULT WINAPI
+    SetThreadDescription(HANDLE hThread, PCWSTR lpThreadDescription);
+    pSetThreadDescription = &SetThreadDescription;
+#endif
+
+    if (utf8towchar(name, &wname) < 0)
+        return ENOMEM;
+
+    hr = pSetThreadDescription(GetCurrentThread(), wname);
+    av_free(wname);
+    return SUCCEEDED(hr) ? 0 : EINVAL;
+}
+
 #endif /* COMPAT_W32PTHREADS_H */
diff --git a/libavutil/thread.h b/libavutil/thread.h
index 2c00c7cc35..d1a36a6772 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 = AVERROR(win32_thread_setname(name));
 #else
     ret = AVERROR(ENOSYS);
 #endif
-- 
2.45.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

             reply	other threads:[~2025-03-04 12:54 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-04 12:52 Kacper Michajłow [this message]
2025-03-04 14:50 ` James Almer
2025-03-04 14:57   ` Kacper Michajlow
2025-03-04 15:07     ` Kacper Michajlow

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250304125249.1879-1-kasper93@gmail.com \
    --to=kasper93@gmail.com \
    --cc=ffmpeg-devel@ffmpeg.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git