raster pushed a commit to branch master.

http://git.enlightenment.org/core/efl.git/commit/?id=5625aac4d4860730428a0bca421f447425292aec

commit 5625aac4d4860730428a0bca421f447425292aec
Author: Carsten Haitzler (Rasterman) <ras...@rasterman.com>
Date:   Wed Sep 9 12:45:47 2015 +0900

    eina thread - add wrapper for setting thread name and fix affinity
    
    added support to set thread names for debugging. this wraps the gnu
    extension to set a thread name of up to 15 chars (16 inc nul byte).
    eina_thread_name_set() is the new api.
    @feature
    
    in the process i found the autofoo wasnt enabling cpu affinity support
    at all in reality, so i had to fix that at the same time.
---
 configure.ac                  |  2 ++
 m4/efl_threads.m4             | 15 +++++++++++++++
 src/lib/eina/eina_config.h.in | 10 ++++++++++
 src/lib/eina/eina_thread.c    | 10 ++++++++++
 src/lib/eina/eina_thread.h    | 17 +++++++++++++++++
 5 files changed, 54 insertions(+)

diff --git a/configure.ac b/configure.ac
index 2d43a72..092a86d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -989,6 +989,7 @@ EFL_ADD_CFLAGS([EINA], [${EFL_PTHREAD_CFLAGS}])
 
 EINA_CONFIG([HAVE_PTHREAD_BARRIER], [test "x${efl_have_pthread_barrier}" = 
"xyes"])
 EINA_CONFIG([HAVE_PTHREAD_AFFINITY], [test "x${efl_have_setaffinity}" = 
"xyes"])
+EINA_CONFIG([HAVE_PTHREAD_SETNAME], [test "x${efl_have_setname}" = "xyes"])
 EINA_CONFIG([HAVE_DEBUG_THREADS], [test "x${want_debug_threads}" = "xyes"])
 EINA_CONFIG([HAVE_POSIX_SPINLOCK], [test "x${efl_have_posix_threads_spinlock}" 
= "xyes"])
 EINA_CONFIG([HAVE_OSX_SPINLOCK], [test "x${efl_have_osx_spinlock}" = "xyes"])
@@ -4847,6 +4848,7 @@ fi
 EFL_ADD_FEATURE([thread], [spinlocks], [${efl_have_spinlock}])
 EFL_ADD_FEATURE([thread], [barrier], [${efl_have_pthread_barrier}])
 EFL_ADD_FEATURE([thread], [affinity], [${efl_have_setaffinity}])
+EFL_ADD_FEATURE([thread], [setname], [${efl_have_setname}])
 
 echo
 echo
diff --git a/m4/efl_threads.m4 b/m4/efl_threads.m4
index 88317af..4ed9ff2 100644
--- a/m4/efl_threads.m4
+++ b/m4/efl_threads.m4
@@ -62,6 +62,17 @@ pthread_attr_setaffinity_np(NULL, 0, NULL);
                        ]])],
       [efl_have_setaffinity="yes"],
       [efl_have_setaffinity="no"])
+   AC_LINK_IFELSE(
+      [AC_LANG_PROGRAM([[
+#define _GNU_SOURCE
+#include <stdlib.h>
+#include <pthread.h>
+                       ]],
+                       [[
+pthread_setname_np(NULL, NULL);
+                       ]])],
+      [efl_have_setname="yes"],
+      [efl_have_setname="no"])
    LIBS=${SAVE_LIBS}
 fi
 
@@ -71,10 +82,14 @@ if test "x${_efl_have_posix_threads}" = "xyes" ; then
 else
    if test "x${_efl_have_win32_threads}" = "xyes" ; then
       efl_have_threads="Windows"
+      efl_have_pthread_affinity="no"
       efl_have_pthread_barrier="no"
+      efl_have_pthread_setname="no"
    else
       efl_have_threads="no"
+      efl_have_pthread_affinity="no"
       efl_have_pthread_barrier="no"
+      efl_have_pthread_setname="no"
    fi
 fi
 AC_MSG_RESULT([${efl_have_threads}])
diff --git a/src/lib/eina/eina_config.h.in b/src/lib/eina/eina_config.h.in
index af65f3b..9ec3b29 100644
--- a/src/lib/eina/eina_config.h.in
+++ b/src/lib/eina/eina_config.h.in
@@ -42,11 +42,21 @@
 #define EINA_HAVE_THREADS
 #endif
 
+#ifdef EINA_HAVE_PTHREAD_AFFINITY
+# undef EINA_HAVE_PTHREAD_AFFINITY
+#endif
+@EINA_CONFIGURE_HAVE_PTHREAD_AFFINITY@
+
 #ifdef EINA_HAVE_PTHREAD_BARRIER
 # undef EINA_HAVE_PTHREAD_BARRIER
 #endif
 @EINA_CONFIGURE_HAVE_PTHREAD_BARRIER@
 
+#ifdef EINA_HAVE_PTHREAD_SETNAME
+# undef EINA_HAVE_PTHREAD_SETNAME
+#endif
+@EINA_CONFIGURE_HAVE_PTHREAD_SETNAME@
+
 #ifdef EINA_HAVE_DEBUG_THREADS
 # undef EINA_HAVE_DEBUG_THREADS
 #endif
diff --git a/src/lib/eina/eina_thread.c b/src/lib/eina/eina_thread.c
index cbc52ad..2730662 100644
--- a/src/lib/eina/eina_thread.c
+++ b/src/lib/eina/eina_thread.c
@@ -25,6 +25,7 @@
 #include "eina_config.h"
 #include "eina_thread.h"
 #include "eina_sched.h"
+#include "eina_cpu.h"
 
 /* undefs EINA_ARG_NONULL() so NULL checks are not compiled out! */
 #include "eina_safety_checks.h"
@@ -169,6 +170,15 @@ eina_thread_join(Eina_Thread t)
    return _eina_thread_join(t);
 }
 
+EAPI Eina_Bool
+eina_thread_name_set(Eina_Thread t, const char *name)
+{
+#ifdef EINA_HAVE_PTHREAD_SETNAME
+   if (pthread_setname_np((pthread_t)t, name) == 0) return EINA_TRUE;
+#endif
+   return EINA_FALSE;
+}
+
 Eina_Bool
 eina_thread_init(void)
 {
diff --git a/src/lib/eina/eina_thread.h b/src/lib/eina/eina_thread.h
index adbf345..6a2c26d 100644
--- a/src/lib/eina/eina_thread.h
+++ b/src/lib/eina/eina_thread.h
@@ -115,6 +115,23 @@ EAPI Eina_Bool eina_thread_create(Eina_Thread *t,
 EAPI void *eina_thread_join(Eina_Thread t);
 
 /**
+ * Set the name of a given thread for debugging purposes.
+ *
+ * This maps to the pthread_setname_np() GNU extension or similar
+ * if available. The name may be limited in size (possibly 16
+ * characters including the nul byte terminator). This is useful
+ * for debugging to name a thread so external tools can display a
+ * meaningful name attached to the thread.
+ *
+ * @param t thread to set the name of
+ * @param name a string to name the thread - this cannot be NULL
+ * @return EINA_TRUE if it succeeds in setting the name or EINA_FALSE
+ *         otherwise.
+ * @since 1.16
+ */
+EAPI Eina_Bool eina_thread_name_set(Eina_Thread t, const char *name);
+
+/**
  * @}
  */
 

-- 


Reply via email to