summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--recipes/glib.recipe2
-rw-r--r--recipes/glib/0001-gthread-win32-Use-SetThreadDescription-Win32-API-for.patch84
2 files changed, 86 insertions, 0 deletions
diff --git a/recipes/glib.recipe b/recipes/glib.recipe
index f8783a67..6d54a653 100644
--- a/recipes/glib.recipe
+++ b/recipes/glib.recipe
@@ -52,6 +52,8 @@ class Recipe(recipe.Recipe):
'glib/0001-glib-Use-g_getenv-everywhere-instead-of-getenv.patch',
# https://gitlab.gnome.org/GNOME/glib/-/merge_requests/1771
'glib/0001-macos-fix-frexpl-checks-in-cross-compilation.patch',
+ # https://gitlab.gnome.org/GNOME/glib/-/merge_requests/1884
+ 'glib/0001-gthread-win32-Use-SetThreadDescription-Win32-API-for.patch',
]
files_libs = [
diff --git a/recipes/glib/0001-gthread-win32-Use-SetThreadDescription-Win32-API-for.patch b/recipes/glib/0001-gthread-win32-Use-SetThreadDescription-Win32-API-for.patch
new file mode 100644
index 00000000..0b64e063
--- /dev/null
+++ b/recipes/glib/0001-gthread-win32-Use-SetThreadDescription-Win32-API-for.patch
@@ -0,0 +1,84 @@
+From 2fd36c88b86173e4ee577009c81eaf83d7ff2d16 Mon Sep 17 00:00:00 2001
+From: Seungha Yang <seungha@centricular.com>
+Date: Fri, 15 Jan 2021 01:21:51 +0900
+Subject: [PATCH] gthread-win32: Use SetThreadDescription Win32 API for setting
+ thread name
+
+Since Windows 10 1607, we can make use of SetThreadDescription() API
+for setting thread name. Unlike previously used exception based
+method, this API will preserve configured thread name on dump file.
+---
+ glib/gthread-win32.c | 54 +++++++++++++++++++++++++++++++++++++++++++-
+ 1 file changed, 53 insertions(+), 1 deletion(-)
+
+diff --git a/glib/gthread-win32.c b/glib/gthread-win32.c
+index 89df0da..8164835 100644
+--- a/glib/gthread-win32.c
++++ b/glib/gthread-win32.c
+@@ -536,10 +536,62 @@ SetThreadName (DWORD dwThreadID,
+ #endif
+ }
+
++typedef HRESULT (WINAPI *pSetThreadDescription) (HANDLE hThread,
++ PCWSTR lpThreadDescription);
++static pSetThreadDescription SetThreadDescriptionFunc = NULL;
++HMODULE kernel32_module = NULL;
++
++static gboolean
++g_thread_win32_load_library (void)
++{
++ /* FIXME: Add support for UWP app */
++#if !defined(G_WINAPI_ONLY_APP)
++ static volatile gsize _init_once = 0;
++ if (g_once_init_enter (&_init_once))
++ {
++ kernel32_module = LoadLibraryW (L"kernel32.dll");
++ if (kernel32_module)
++ {
++ SetThreadDescriptionFunc =
++ (pSetThreadDescription) GetProcAddress (kernel32_module,
++ "SetThreadDescription");
++ if (!SetThreadDescriptionFunc)
++ FreeLibrary (kernel32_module);
++ }
++ g_once_init_leave (&_init_once, 1);
++ }
++#endif
++
++ return !!SetThreadDescriptionFunc;
++}
++
++static gboolean
++g_thread_win32_set_thread_desc (const gchar *name)
++{
++ HRESULT hr;
++ wchar_t *namew;
++
++ if (!g_thread_win32_load_library () || !name)
++ return FALSE;
++
++ namew = g_utf8_to_utf16 (name, -1, NULL, NULL, NULL);
++ if (!namew)
++ return FALSE;
++
++ hr = SetThreadDescriptionFunc (GetCurrentThread (), namew);
++
++ g_free (namew);
++ return SUCCEEDED (hr);
++}
++
+ void
+ g_system_thread_set_name (const gchar *name)
+ {
+- SetThreadName ((DWORD) -1, name);
++ /* Prefer SetThreadDescription over exception based way if available,
++ * since thread description set by SetThreadDescription will be preserved
++ * in dump file */
++ if (!g_thread_win32_set_thread_desc (name))
++ SetThreadName ((DWORD) -1, name);
+ }
+
+ /* {{{1 Epilogue */
+--
+2.29.2
+