From 0bebaed0acd3b07d2d85e0269344f628a5d9e575 Mon Sep 17 00:00:00 2001 From: Tom Hacohen Date: Fri, 16 Oct 2015 15:13:51 +0100 Subject: [PATCH] Eo do: use the __thread directive when available to manage call stack. This is faster in most cases, and to be honest, should be much faster than it is. I don't understand why there's no better directive to mark a variable as *really* important thread storage that is used all the time. --- configure.ac | 15 +++++++++++++++ src/lib/eo/eo.c | 14 +++++++++++--- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/configure.ac b/configure.ac index 5ecbcac4f6..f0980adf7b 100644 --- a/configure.ac +++ b/configure.ac @@ -984,6 +984,20 @@ if test "x${efl_have_threads}" = "xno"; then CFOPT_WARNING="xyes" fi +AC_COMPILE_IFELSE( + [AC_LANG_PROGRAM( + [[ ]], + [[ + static __thread int a = 0; + ]])], + [have_thread_specifier="yes"], + [have_thread_specifier="no"]) +AC_MSG_CHECKING([for __thread specifier]) +AC_MSG_RESULT([${have_thread_specifier}]) +if test "x${have_thread_specifier}" = "xyes" ; then + AC_DEFINE([HAVE_THREAD_SPECIFIER], [1], [Have the __thread specifier]) +fi + EFL_ADD_PUBLIC_LIBS([EINA], [${EFL_PTHREAD_LIBS}]) EFL_ADD_CFLAGS([EINA], [${EFL_PTHREAD_CFLAGS}]) @@ -4868,6 +4882,7 @@ 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}]) +EFL_ADD_FEATURE([thread], [__thread], [${have_thread_specifier}]) echo echo diff --git a/src/lib/eo/eo.c b/src/lib/eo/eo.c index 4b33c2c111..fd1fc2a3a3 100644 --- a/src/lib/eo/eo.c +++ b/src/lib/eo/eo.c @@ -375,6 +375,13 @@ _eo_call_stack_free(void *ptr) free(stack); } +#ifdef HAVE_THREAD_SPECIFIER +static __thread Eo_Call_Stack *_eo_thread_stack = NULL; + +#define _EO_CALL_STACK_GET() ((_eo_thread_stack) ? _eo_thread_stack : (_eo_thread_stack = _eo_call_stack_create())) + +#else + static Eo_Call_Stack *main_loop_stack = NULL; #define _EO_CALL_STACK_GET() ((EINA_LIKELY(eina_main_loop_is())) ? main_loop_stack : _eo_call_stack_get_thread()) @@ -382,9 +389,7 @@ static Eo_Call_Stack *main_loop_stack = NULL; static inline Eo_Call_Stack * _eo_call_stack_get_thread(void) { - Eo_Call_Stack *stack; - - stack = eina_tls_get(_eo_call_stack_key); + Eo_Call_Stack *stack = eina_tls_get(_eo_call_stack_key); if (stack) return stack; @@ -393,6 +398,7 @@ _eo_call_stack_get_thread(void) return stack; } +#endif EAPI EINA_CONST void * _eo_stack_get(void) @@ -1826,12 +1832,14 @@ eo_init(void) } } +#ifndef HAVE_THREAD_SPECIFIER main_loop_stack = _eo_call_stack_create(); if (!main_loop_stack) { EINA_LOG_ERR("Could not alloc eo call stack."); return EINA_FALSE; } +#endif return EINA_TRUE; }