summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarsten Haitzler (Rasterman) <raster@rasterman.com>2015-09-09 12:45:47 +0900
committerCarsten Haitzler (Rasterman) <raster@rasterman.com>2015-09-09 12:45:47 +0900
commit5625aac4d4860730428a0bca421f447425292aec (patch)
tree53049cbf421cea4b8f83b7b88f36729182b550d1
parent712db856a2738505f245f2c0c98b3419993246de (diff)
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.
-rw-r--r--configure.ac2
-rw-r--r--m4/efl_threads.m415
-rw-r--r--src/lib/eina/eina_config.h.in10
-rw-r--r--src/lib/eina/eina_thread.c10
-rw-r--r--src/lib/eina/eina_thread.h17
5 files changed, 54 insertions, 0 deletions
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}])
989 989
990EINA_CONFIG([HAVE_PTHREAD_BARRIER], [test "x${efl_have_pthread_barrier}" = "xyes"]) 990EINA_CONFIG([HAVE_PTHREAD_BARRIER], [test "x${efl_have_pthread_barrier}" = "xyes"])
991EINA_CONFIG([HAVE_PTHREAD_AFFINITY], [test "x${efl_have_setaffinity}" = "xyes"]) 991EINA_CONFIG([HAVE_PTHREAD_AFFINITY], [test "x${efl_have_setaffinity}" = "xyes"])
992EINA_CONFIG([HAVE_PTHREAD_SETNAME], [test "x${efl_have_setname}" = "xyes"])
992EINA_CONFIG([HAVE_DEBUG_THREADS], [test "x${want_debug_threads}" = "xyes"]) 993EINA_CONFIG([HAVE_DEBUG_THREADS], [test "x${want_debug_threads}" = "xyes"])
993EINA_CONFIG([HAVE_POSIX_SPINLOCK], [test "x${efl_have_posix_threads_spinlock}" = "xyes"]) 994EINA_CONFIG([HAVE_POSIX_SPINLOCK], [test "x${efl_have_posix_threads_spinlock}" = "xyes"])
994EINA_CONFIG([HAVE_OSX_SPINLOCK], [test "x${efl_have_osx_spinlock}" = "xyes"]) 995EINA_CONFIG([HAVE_OSX_SPINLOCK], [test "x${efl_have_osx_spinlock}" = "xyes"])
@@ -4847,6 +4848,7 @@ fi
4847EFL_ADD_FEATURE([thread], [spinlocks], [${efl_have_spinlock}]) 4848EFL_ADD_FEATURE([thread], [spinlocks], [${efl_have_spinlock}])
4848EFL_ADD_FEATURE([thread], [barrier], [${efl_have_pthread_barrier}]) 4849EFL_ADD_FEATURE([thread], [barrier], [${efl_have_pthread_barrier}])
4849EFL_ADD_FEATURE([thread], [affinity], [${efl_have_setaffinity}]) 4850EFL_ADD_FEATURE([thread], [affinity], [${efl_have_setaffinity}])
4851EFL_ADD_FEATURE([thread], [setname], [${efl_have_setname}])
4850 4852
4851echo 4853echo
4852echo 4854echo
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);
62 ]])], 62 ]])],
63 [efl_have_setaffinity="yes"], 63 [efl_have_setaffinity="yes"],
64 [efl_have_setaffinity="no"]) 64 [efl_have_setaffinity="no"])
65 AC_LINK_IFELSE(
66 [AC_LANG_PROGRAM([[
67#define _GNU_SOURCE
68#include <stdlib.h>
69#include <pthread.h>
70 ]],
71 [[
72pthread_setname_np(NULL, NULL);
73 ]])],
74 [efl_have_setname="yes"],
75 [efl_have_setname="no"])
65 LIBS=${SAVE_LIBS} 76 LIBS=${SAVE_LIBS}
66fi 77fi
67 78
@@ -71,10 +82,14 @@ if test "x${_efl_have_posix_threads}" = "xyes" ; then
71else 82else
72 if test "x${_efl_have_win32_threads}" = "xyes" ; then 83 if test "x${_efl_have_win32_threads}" = "xyes" ; then
73 efl_have_threads="Windows" 84 efl_have_threads="Windows"
85 efl_have_pthread_affinity="no"
74 efl_have_pthread_barrier="no" 86 efl_have_pthread_barrier="no"
87 efl_have_pthread_setname="no"
75 else 88 else
76 efl_have_threads="no" 89 efl_have_threads="no"
90 efl_have_pthread_affinity="no"
77 efl_have_pthread_barrier="no" 91 efl_have_pthread_barrier="no"
92 efl_have_pthread_setname="no"
78 fi 93 fi
79fi 94fi
80AC_MSG_RESULT([${efl_have_threads}]) 95AC_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 @@
42#define EINA_HAVE_THREADS 42#define EINA_HAVE_THREADS
43#endif 43#endif
44 44
45#ifdef EINA_HAVE_PTHREAD_AFFINITY
46# undef EINA_HAVE_PTHREAD_AFFINITY
47#endif
48@EINA_CONFIGURE_HAVE_PTHREAD_AFFINITY@
49
45#ifdef EINA_HAVE_PTHREAD_BARRIER 50#ifdef EINA_HAVE_PTHREAD_BARRIER
46# undef EINA_HAVE_PTHREAD_BARRIER 51# undef EINA_HAVE_PTHREAD_BARRIER
47#endif 52#endif
48@EINA_CONFIGURE_HAVE_PTHREAD_BARRIER@ 53@EINA_CONFIGURE_HAVE_PTHREAD_BARRIER@
49 54
55#ifdef EINA_HAVE_PTHREAD_SETNAME
56# undef EINA_HAVE_PTHREAD_SETNAME
57#endif
58@EINA_CONFIGURE_HAVE_PTHREAD_SETNAME@
59
50#ifdef EINA_HAVE_DEBUG_THREADS 60#ifdef EINA_HAVE_DEBUG_THREADS
51# undef EINA_HAVE_DEBUG_THREADS 61# undef EINA_HAVE_DEBUG_THREADS
52#endif 62#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 @@
25#include "eina_config.h" 25#include "eina_config.h"
26#include "eina_thread.h" 26#include "eina_thread.h"
27#include "eina_sched.h" 27#include "eina_sched.h"
28#include "eina_cpu.h"
28 29
29/* undefs EINA_ARG_NONULL() so NULL checks are not compiled out! */ 30/* undefs EINA_ARG_NONULL() so NULL checks are not compiled out! */
30#include "eina_safety_checks.h" 31#include "eina_safety_checks.h"
@@ -169,6 +170,15 @@ eina_thread_join(Eina_Thread t)
169 return _eina_thread_join(t); 170 return _eina_thread_join(t);
170} 171}
171 172
173EAPI Eina_Bool
174eina_thread_name_set(Eina_Thread t, const char *name)
175{
176#ifdef EINA_HAVE_PTHREAD_SETNAME
177 if (pthread_setname_np((pthread_t)t, name) == 0) return EINA_TRUE;
178#endif
179 return EINA_FALSE;
180}
181
172Eina_Bool 182Eina_Bool
173eina_thread_init(void) 183eina_thread_init(void)
174{ 184{
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,
115EAPI void *eina_thread_join(Eina_Thread t); 115EAPI void *eina_thread_join(Eina_Thread t);
116 116
117/** 117/**
118 * Set the name of a given thread for debugging purposes.
119 *
120 * This maps to the pthread_setname_np() GNU extension or similar
121 * if available. The name may be limited in size (possibly 16
122 * characters including the nul byte terminator). This is useful
123 * for debugging to name a thread so external tools can display a
124 * meaningful name attached to the thread.
125 *
126 * @param t thread to set the name of
127 * @param name a string to name the thread - this cannot be NULL
128 * @return EINA_TRUE if it succeeds in setting the name or EINA_FALSE
129 * otherwise.
130 * @since 1.16
131 */
132EAPI Eina_Bool eina_thread_name_set(Eina_Thread t, const char *name);
133
134/**
118 * @} 135 * @}
119 */ 136 */
120 137