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 52908f397f)
This commit is contained in:
parent
58dccd6cf5
commit
ca8bbd2e3d
1 changed files with 25 additions and 13 deletions
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue