ecore: merge call to main loop together to reduce number of main loop wakeup.
authorcedric <cedric@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Mon, 1 Aug 2011 12:16:39 +0000 (12:16 +0000)
committercedric <cedric@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Mon, 1 Aug 2011 12:16:39 +0000 (12:16 +0000)
git-svn-id: http://svn.enlightenment.org/svn/e/trunk/ecore@61947 7cbeb6ba-43b4-40fd-8cce-4c39aea84d33

src/lib/ecore/ecore.c

index d4d2f73..a1d0d3c 100644 (file)
@@ -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;
+
+   eina_lock_take(&_thread_safety);
+   callback = _thread_cb;
+   _thread_cb = NULL;
+   eina_lock_release(&_thread_safety);
 
-   while (nbyte >= sizeof (Ecore_Safe_Call*))
+   EINA_LIST_FREE(callback, call)
      {
         call->cb(call->data);
         free(call);
-
-        call++;
-        nbyte -= sizeof (Ecore_Safe_Call*);
      }
 }