forked from enlightenment/efl
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.
This commit is contained in:
parent
712db856a2
commit
5625aac4d4
|
@ -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
|
||||
|
|
|
@ -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}])
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue