Commit ca8bbd2e authored by Ell's avatar Ell
Browse files

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.

(cherry picked from commit 52908f39)
parent 58dccd6c
...@@ -85,9 +85,12 @@ static inline gint gimp_backtrace_normalize_frame (GimpBacktrace *back ...@@ -85,9 +85,12 @@ static inline gint gimp_backtrace_normalize_frame (GimpBacktrace *back
gint thread, gint thread,
gint frame); gint frame);
static void gimp_backtrace_set_thread_name (DWORD tid,
const gchar *name);
static gboolean gimp_backtrace_enumerate_threads (void); 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 */ /* static variables */
...@@ -133,6 +136,24 @@ gimp_backtrace_normalize_frame (GimpBacktrace *backtrace, ...@@ -133,6 +136,24 @@ gimp_backtrace_normalize_frame (GimpBacktrace *backtrace,
return backtrace->threads[thread].n_frames + frame; 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 static gboolean
gimp_backtrace_enumerate_threads (void) gimp_backtrace_enumerate_threads (void)
{ {
...@@ -231,18 +252,7 @@ gimp_backtrace_exception_handler (PEXCEPTION_POINTERS info) ...@@ -231,18 +252,7 @@ gimp_backtrace_exception_handler (PEXCEPTION_POINTERS info)
if (tid == -1) if (tid == -1)
tid = GetCurrentThreadId (); tid = GetCurrentThreadId ();
while (! g_atomic_int_compare_and_exchange (&thread_names_spinlock, gimp_backtrace_set_thread_name (tid, name_info.szName);
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);
return EXCEPTION_CONTINUE_EXECUTION; return EXCEPTION_CONTINUE_EXECUTION;
} }
...@@ -260,6 +270,8 @@ gimp_backtrace_exception_handler (PEXCEPTION_POINTERS info) ...@@ -260,6 +270,8 @@ gimp_backtrace_exception_handler (PEXCEPTION_POINTERS info)
void void
gimp_backtrace_init (void) gimp_backtrace_init (void)
{ {
gimp_backtrace_set_thread_name (GetCurrentThreadId (), g_get_prgname ());
AddVectoredExceptionHandler (TRUE, gimp_backtrace_exception_handler); AddVectoredExceptionHandler (TRUE, gimp_backtrace_exception_handler);
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment