summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Hacohen <tom@stosb.com>2015-10-16 15:13:51 +0100
committerTom Hacohen <tom@stosb.com>2015-10-19 10:22:41 +0100
commitb9a6a8e7384fc79fced2132407208abfedf77fe1 (patch)
tree4878ab1a8abfc9573a8a2518fa21e02c4198cb51
parent38a059420dcbc8b3d1a6b15b968da7ab6e1c1792 (diff)
downloadefl-b9a6a8e7384fc79fced2132407208abfedf77fe1.tar.gz
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 69edd17f76..cb8e9505c6 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 bc71108963..ee72b742e6 100644
--- a/src/lib/eo/eo.c
+++ b/src/lib/eo/eo.c
@@ -378,6 +378,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())
@@ -385,9 +392,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;
@@ -396,6 +401,7 @@ _eo_call_stack_get_thread(void)
return stack;
}
+#endif
EAPI EINA_CONST void *
_eo_stack_get(void)
@@ -1777,12 +1783,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;
}