From d0e8b833a94a632c4c5e0345107550099ccb0fe7 Mon Sep 17 00:00:00 2001 From: Cedric BAIL Date: Mon, 1 Aug 2011 12:16:39 +0000 Subject: [PATCH] ecore: merge call to main loop together to reduce number of main loop wakeup. SVN revision: 61947 --- legacy/ecore/src/lib/ecore/ecore.c | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/legacy/ecore/src/lib/ecore/ecore.c b/legacy/ecore/src/lib/ecore/ecore.c index d4d2f739c4..a1d0d3cab8 100644 --- a/legacy/ecore/src/lib/ecore/ecore.c +++ b/legacy/ecore/src/lib/ecore/ecore.c @@ -61,6 +61,7 @@ struct _Ecore_Safe_Call }; static void _thread_callback(void *data, void *buffer, unsigned int nbyte); +static Eina_List *_thread_cb = NULL; static Ecore_Pipe *_thread_call = NULL; static Eina_Lock _thread_safety; @@ -224,6 +225,8 @@ EAPI void ecore_main_loop_thread_safe_call(Ecore_Cb callback, void *data) { Ecore_Safe_Call *order; + int wakeup = 42; + Eina_Bool count; if (eina_main_loop_is()) { @@ -238,7 +241,11 @@ ecore_main_loop_thread_safe_call(Ecore_Cb callback, void *data) order->data = data; eina_lock_take(&_thread_safety); - ecore_pipe_write(_thread_call, &order, sizeof (Ecore_Safe_Call*)); + + count = _thread_cb ? 0 : 1; + _thread_cb = eina_list_append(_thread_cb, order); + if (count) ecore_pipe_write(_thread_call, &wakeup, sizeof (int)); + eina_lock_release(&_thread_safety); } @@ -469,16 +476,21 @@ _ecore_memory_statistic(__UNUSED__ void *data) #endif static void -_thread_callback(void *data __UNUSED__, void *buffer, unsigned int nbyte) +_thread_callback(void *data __UNUSED__, + void *buffer __UNUSED__, + unsigned int nbyte __UNUSED__) { - Ecore_Safe_Call *call = buffer; + Ecore_Safe_Call *call; + Eina_List *callback; - while (nbyte >= sizeof (Ecore_Safe_Call*)) + eina_lock_take(&_thread_safety); + callback = _thread_cb; + _thread_cb = NULL; + eina_lock_release(&_thread_safety); + + EINA_LIST_FREE(callback, call) { call->cb(call->data); free(call); - - call++; - nbyte -= sizeof (Ecore_Safe_Call*); } }