[gimp] app: in GimpBacktrace Windows backend, set main-thread name



commit 52908f397f33b23104e794f772476653b4cea0ec
Author: Ell <ell_se yahoo com>
Date:   Wed Oct 10 09:44:07 2018 -0400

    app: in GimpBacktrace Windows backend, set main-thread name
    
    When initializing the GimpBacktrace Windows backend, set the name
    of the current thread (which is assumed to be the main thread) to
    the program's name, to match its name on Linux.  We normally rely
    on the SET_THREAD_NAME exception to set thread names on Windows,
    which isn't raised for the main thread.

 app/core/gimpbacktrace-windows.c | 38 +++++++++++++++++++++++++-------------
 1 file changed, 25 insertions(+), 13 deletions(-)
---
diff --git a/app/core/gimpbacktrace-windows.c b/app/core/gimpbacktrace-windows.c
index d606e49ffe..dceb8834a6 100644
--- a/app/core/gimpbacktrace-windows.c
+++ b/app/core/gimpbacktrace-windows.c
@@ -85,9 +85,12 @@ static inline gint   gimp_backtrace_normalize_frame   (GimpBacktrace       *back
                                                        gint                 thread,
                                                        gint                 frame);
 
+static void          gimp_backtrace_set_thread_name   (DWORD                tid,
+                                                       const gchar         *name);
+
 static gboolean      gimp_backtrace_enumerate_threads (void);
 
-static LONG          gimp_backtrace_exception_handler (PEXCEPTION_POINTERS info);
+static LONG          gimp_backtrace_exception_handler (PEXCEPTION_POINTERS  info);
 
 
 /*  static variables  */
@@ -133,6 +136,24 @@ gimp_backtrace_normalize_frame (GimpBacktrace *backtrace,
     return backtrace->threads[thread].n_frames + frame;
 }
 
+static void
+gimp_backtrace_set_thread_name (DWORD        tid,
+                                const gchar *name)
+{
+  while (! g_atomic_int_compare_and_exchange (&thread_names_spinlock,
+                                              0, 1));
+
+  if (n_thread_names < MAX_N_THREADS)
+    {
+      Thread *thread = &thread_names[n_thread_names++];
+
+      thread->tid  = tid;
+      thread->name = g_strdup (name);
+    }
+
+  g_atomic_int_set (&thread_names_spinlock, 0);
+}
+
 static gboolean
 gimp_backtrace_enumerate_threads (void)
 {
@@ -231,18 +252,7 @@ gimp_backtrace_exception_handler (PEXCEPTION_POINTERS info)
           if (tid == -1)
             tid = GetCurrentThreadId ();
 
-          while (! g_atomic_int_compare_and_exchange (&thread_names_spinlock,
-                                                      0, 1));
-
-          if (n_thread_names < MAX_N_THREADS)
-            {
-              Thread *thread = &thread_names[n_thread_names++];
-
-              thread->tid  = tid;
-              thread->name = g_strdup (name_info.szName);
-            }
-
-          g_atomic_int_set (&thread_names_spinlock, 0);
+          gimp_backtrace_set_thread_name (tid, name_info.szName);
 
           return EXCEPTION_CONTINUE_EXECUTION;
         }
@@ -260,6 +270,8 @@ gimp_backtrace_exception_handler (PEXCEPTION_POINTERS info)
 void
 gimp_backtrace_init (void)
 {
+  gimp_backtrace_set_thread_name (GetCurrentThreadId (), g_get_prgname ());
+
   AddVectoredExceptionHandler (TRUE, gimp_backtrace_exception_handler);
 }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]