From d99ca361de44136bc105c11bc089ec9dbf420279 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Andre Date: Fri, 6 Nov 2015 18:34:50 +0900 Subject: [PATCH] Eina: Micro-optimize eina_main_loop_is This is useful when Eo calls it to get the current frame stack. This improves the performance of this function by ~50% which meant from ~3% total CPU time to ~1.5% CPU time (if called at each eo_do). Now this patch is a bit irrelevant since eo uses __thread instead. This optimization is still useful for evas_eglGetCurrentXXX. --- src/lib/eina/eina_main.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/lib/eina/eina_main.c b/src/lib/eina/eina_main.c index 1daa795e87..ffb017767e 100644 --- a/src/lib/eina/eina_main.c +++ b/src/lib/eina/eina_main.c @@ -416,7 +416,13 @@ EAPI Eina_Bool eina_main_loop_is(void) { #ifdef EFL_HAVE_THREADS - if (pthread_equal(_eina_main_loop, pthread_self())) +# ifdef __GNUC__ + /* pthread_self() can't be optimized, it's a single asm "movl" */ + if (__builtin_types_compatible_p(pthread_t, unsigned long int)) + return (pthread_self() == _eina_main_loop); + else +# endif + if (pthread_equal(_eina_main_loop, pthread_self())) return EINA_TRUE; #endif return EINA_FALSE;