diff --git a/configure.ac b/configure.ac index 2d43a723aa..092a86dff2 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 88317af8db..4ed9ff25a9 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 +#include + ]], + [[ +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 af65f3b6b6..9ec3b29372 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 cbc52ade83..2730662cd9 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 adbf34566b..6a2c26d02d 100644 --- a/src/lib/eina/eina_thread.h +++ b/src/lib/eina/eina_thread.h @@ -114,6 +114,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); + /** * @} */