summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Hacohen <tom@stosb.com>2015-10-16 15:13:51 +0100
committerTom Hacohen <tom@stosb.com>2015-11-09 11:43:04 +0000
commit0bebaed0acd3b07d2d85e0269344f628a5d9e575 (patch)
tree495f6e9d70a859c18e7c73a1461c364e923b52ac
parent3e40b45be65b21a9941a1531c721216c3301d7a8 (diff)
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.
-rw-r--r--configure.ac15
-rw-r--r--src/lib/eo/eo.c14
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
984 CFOPT_WARNING="xyes" 984 CFOPT_WARNING="xyes"
985fi 985fi
986 986
987AC_COMPILE_IFELSE(
988 [AC_LANG_PROGRAM(
989 [[ ]],
990 [[
991 static __thread int a = 0;
992 ]])],
993 [have_thread_specifier="yes"],
994 [have_thread_specifier="no"])
995AC_MSG_CHECKING([for __thread specifier])
996AC_MSG_RESULT([${have_thread_specifier}])
997if test "x${have_thread_specifier}" = "xyes" ; then
998 AC_DEFINE([HAVE_THREAD_SPECIFIER], [1], [Have the __thread specifier])
999fi
1000
987EFL_ADD_PUBLIC_LIBS([EINA], [${EFL_PTHREAD_LIBS}]) 1001EFL_ADD_PUBLIC_LIBS([EINA], [${EFL_PTHREAD_LIBS}])
988EFL_ADD_CFLAGS([EINA], [${EFL_PTHREAD_CFLAGS}]) 1002EFL_ADD_CFLAGS([EINA], [${EFL_PTHREAD_CFLAGS}])
989 1003
@@ -4868,6 +4882,7 @@ EFL_ADD_FEATURE([thread], [spinlocks], [${efl_have_spinlock}])
4868EFL_ADD_FEATURE([thread], [barrier], [${efl_have_pthread_barrier}]) 4882EFL_ADD_FEATURE([thread], [barrier], [${efl_have_pthread_barrier}])
4869EFL_ADD_FEATURE([thread], [affinity], [${efl_have_setaffinity}]) 4883EFL_ADD_FEATURE([thread], [affinity], [${efl_have_setaffinity}])
4870EFL_ADD_FEATURE([thread], [setname], [${efl_have_setname}]) 4884EFL_ADD_FEATURE([thread], [setname], [${efl_have_setname}])
4885EFL_ADD_FEATURE([thread], [__thread], [${have_thread_specifier}])
4871 4886
4872echo 4887echo
4873echo 4888echo
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)
375 free(stack); 375 free(stack);
376} 376}
377 377
378#ifdef HAVE_THREAD_SPECIFIER
379static __thread Eo_Call_Stack *_eo_thread_stack = NULL;
380
381#define _EO_CALL_STACK_GET() ((_eo_thread_stack) ? _eo_thread_stack : (_eo_thread_stack = _eo_call_stack_create()))
382
383#else
384
378static Eo_Call_Stack *main_loop_stack = NULL; 385static Eo_Call_Stack *main_loop_stack = NULL;
379 386
380#define _EO_CALL_STACK_GET() ((EINA_LIKELY(eina_main_loop_is())) ? main_loop_stack : _eo_call_stack_get_thread()) 387#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;
382static inline Eo_Call_Stack * 389static inline Eo_Call_Stack *
383_eo_call_stack_get_thread(void) 390_eo_call_stack_get_thread(void)
384{ 391{
385 Eo_Call_Stack *stack; 392 Eo_Call_Stack *stack = eina_tls_get(_eo_call_stack_key);
386
387 stack = eina_tls_get(_eo_call_stack_key);
388 393
389 if (stack) return stack; 394 if (stack) return stack;
390 395
@@ -393,6 +398,7 @@ _eo_call_stack_get_thread(void)
393 398
394 return stack; 399 return stack;
395} 400}
401#endif
396 402
397EAPI EINA_CONST void * 403EAPI EINA_CONST void *
398_eo_stack_get(void) 404_eo_stack_get(void)
@@ -1826,12 +1832,14 @@ eo_init(void)
1826 } 1832 }
1827 } 1833 }
1828 1834
1835#ifndef HAVE_THREAD_SPECIFIER
1829 main_loop_stack = _eo_call_stack_create(); 1836 main_loop_stack = _eo_call_stack_create();
1830 if (!main_loop_stack) 1837 if (!main_loop_stack)
1831 { 1838 {
1832 EINA_LOG_ERR("Could not alloc eo call stack."); 1839 EINA_LOG_ERR("Could not alloc eo call stack.");
1833 return EINA_FALSE; 1840 return EINA_FALSE;
1834 } 1841 }
1842#endif
1835 1843
1836 return EINA_TRUE; 1844 return EINA_TRUE;
1837} 1845}