[gimp] libgimpbase: Find thread ID on FreeBSD with thr_self



commit 077036273cefd0206c73dc2df03c7d93b860c1a0
Author: Ting-Wei Lan <lantw src gnome org>
Date:   Sat Apr 28 20:57:46 2018 +0800

    libgimpbase: Find thread ID on FreeBSD with thr_self
    
    https://bugzilla.gnome.org/show_bug.cgi?id=795510

 configure.ac            |    3 ++-
 libgimpbase/gimputils.c |   11 +++++++++--
 2 files changed, 11 insertions(+), 3 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 955c56f..a4f2581 100644
--- a/configure.ac
+++ b/configure.ac
@@ -568,7 +568,7 @@ AC_HEADER_STDC
 AC_HEADER_SYS_WAIT
 AC_HEADER_TIME
 
-AC_CHECK_HEADERS(execinfo.h fcntl.h sys/param.h sys/prctl.h sys/time.h sys/times.h sys/wait.h unistd.h)
+AC_CHECK_HEADERS(execinfo.h fcntl.h sys/param.h sys/prctl.h sys/thr.h sys/time.h sys/times.h sys/wait.h 
unistd.h)
 AC_CHECK_FUNCS(backtrace, , AC_CHECK_LIB(execinfo, backtrace))
 
 AC_TYPE_PID_T
@@ -579,6 +579,7 @@ AC_FUNC_ALLOCA
 # check some more funcs
 AC_CHECK_FUNCS(fsync)
 AC_CHECK_FUNCS(difftime mmap)
+AC_CHECK_FUNCS(thr_self)
 
 
 AM_BINRELOC
diff --git a/libgimpbase/gimputils.c b/libgimpbase/gimputils.c
index d95528f..c40314a 100644
--- a/libgimpbase/gimputils.c
+++ b/libgimpbase/gimputils.c
@@ -62,6 +62,10 @@
 #include <sys/prctl.h>
 #endif
 
+#ifdef HAVE_SYS_THR_H
+#include <sys/thr.h>
+#endif
+
 #endif /* G_OS_WIN32 */
 
 #include "gimpbasetypes.h"
@@ -1180,6 +1184,9 @@ gimp_stack_trace_print (const gchar   *prog_name,
   DWORD    tid = GetCurrentThreadId ();
 #elif defined(SYS_gettid)
   long     tid = syscall (SYS_gettid);
+#elif defined(HAVE_THR_SELF)
+  long     tid = 0;
+  thr_self (&tid);
 #endif
 
   g_snprintf (gimp_pid, 16, "%u", (guint) pid);
@@ -1272,7 +1279,7 @@ gimp_stack_trace_print (const gchar   *prog_name,
         {
           if (! stack_printed)
             {
-#if defined(G_OS_WIN32) || defined(SYS_gettid)
+#if defined(G_OS_WIN32) || defined(SYS_gettid) || defined(HAVE_THR_SELF)
               if (stream)
                 g_fprintf (stream,
                            "\n# Stack traces obtained from PID %d - Thread %lu #\n\n",
@@ -1281,7 +1288,7 @@ gimp_stack_trace_print (const gchar   *prog_name,
               if (trace)
                 {
                   gtrace = g_string_new (NULL);
-#if defined(G_OS_WIN32) || defined(SYS_gettid)
+#if defined(G_OS_WIN32) || defined(SYS_gettid) || defined(HAVE_THR_SELF)
                   g_string_printf (gtrace,
                                    "\n# Stack traces obtained from PID %d - Thread %lu #\n\n",
                                    pid, tid);


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