ecore/efl loop - refactor idle stuff to be less convluted when
authorCarsten Haitzler (Rasterman) <raster@rasterman.com>
Thu, 21 Dec 2017 10:31:24 +0000 (19:31 +0900)
committerWonki Kim <wonki_.kim@samsung.com>
Wed, 10 Jan 2018 11:08:13 +0000 (20:08 +0900)
less jumping around the codebase and no need for a message exists
method on the loop as we can find out internally, so only the process
left.

src/lib/ecore/ecore_idle_enterer.c
src/lib/ecore/ecore_idle_exiter.c
src/lib/ecore/ecore_idler.c
src/lib/ecore/ecore_main.c
src/lib/ecore/ecore_private.h
src/lib/ecore/efl_loop.c

index 08e7d9d..9ce4716 100644 (file)
@@ -41,9 +41,3 @@ ecore_idle_enterer_del(Ecore_Idle_Enterer *idle_enterer)
 {
    return _ecore_factorized_idle_del(idle_enterer);
 }
-
-void
-_ecore_idle_enterer_call(Eo *loop)
-{
-   efl_event_callback_call(loop, EFL_LOOP_EVENT_IDLE_ENTER, NULL);
-}
index 8295af2..9ca26c8 100644 (file)
@@ -25,9 +25,3 @@ ecore_idle_exiter_del(Ecore_Idle_Exiter *idle_exiter)
 {
    return _ecore_factorized_idle_del(idle_exiter);
 }
-
-void
-_ecore_idle_exiter_call(Eo *loop)
-{
-   efl_event_callback_call(loop, EFL_LOOP_EVENT_IDLE_EXIT, NULL);
-}
index 70795f8..ffd4579 100644 (file)
@@ -117,22 +117,3 @@ ecore_idler_del(Ecore_Idler *idler)
 {
    return _ecore_factorized_idle_del(idler);
 }
-
-void
-_ecore_idler_all_call(Eo *loop)
-{
-   efl_event_callback_call(loop, EFL_LOOP_EVENT_IDLE, NULL);
-   // just spin in an idler until the free queue is empty freeing 84 items
-   // from the free queue each time.for now this seems like an ok balance
-   // between going in and out of a reduce func with mutexes around it
-   // vs blocking mainloop for too long. this number is up for discussion
-   eina_freeq_reduce(eina_freeq_main_get(), 84);
-}
-
-int
-_ecore_idler_exist(Eo *loop)
-{
-   Efl_Loop_Data *dt = efl_data_scope_get(loop, EFL_LOOP_CLASS);
-
-   return dt->idlers || eina_freeq_ptr_pending(eina_freeq_main_get());
-}
index 7c0c310..829535b 100644 (file)
@@ -337,10 +337,10 @@ _ecore_main_uv_poll_cb(uv_poll_t *handle, int status, int events)
 
    if (_ecore_main_uv_idling)
      {
-       DBG("not IDLE anymore");
-       _ecore_main_uv_idling = EINA_FALSE;
-       _ecore_idle_exiter_call(obj);
-       _ecore_animator_run_reset();
+        DBG("not IDLE anymore");
+        _ecore_main_uv_idling = EINA_FALSE;
+        efl_event_callback_call(obj, EFL_LOOP_EVENT_IDLE_EXIT, NULL);
+        _ecore_animator_run_reset();
      }
 
   if (status)               fdh->error_active = EINA_TRUE;
@@ -516,6 +516,23 @@ _ecore_main_fdh_poll_modify(Efl_Loop_Data *pd EINA_UNUSED, Ecore_Fd_Handler *fdh
    return r;
 }
 
+static Eina_Bool
+_ecore_main_idlers_exist(Efl_Loop_Data *pd)
+{
+   return pd->idlers || eina_freeq_ptr_pending(eina_freeq_main_get());
+}
+
+static void
+_ecore_main_idler_all_call(Eo *loop)
+{
+   efl_event_callback_call(loop, EFL_LOOP_EVENT_IDLE, NULL);
+   // just spin in an idler until the free queue is empty freeing 84 items
+   // from the free queue each time.for now this seems like an ok balance
+   // between going in and out of a reduce func with mutexes around it
+   // vs blocking mainloop for too long. this number is up for discussion
+   eina_freeq_reduce(eina_freeq_main_get(), 84);
+}
+
 #ifdef HAVE_EPOLL
 static inline int
 _ecore_main_fdh_epoll_mark_active(Eo *obj, Efl_Loop_Data *pd)
@@ -661,7 +678,7 @@ _ecore_main_gsource_prepare(GSource *source EINA_UNUSED,
         pd->loop_time = _ecore_time_loop_time = ecore_time_get();
         _efl_loop_timer_expired_timers_call(obj, pd, pd->loop_time);
 
-        _ecore_idle_enterer_call(obj);
+        efl_event_callback_call(obj, EFL_LOOP_EVENT_IDLE_ENTER, NULL);
         _ecore_throttle();
         _throttle_do(pd);
         _ecore_glib_idle_enterer_called = FALSE;
@@ -676,8 +693,8 @@ _ecore_main_gsource_prepare(GSource *source EINA_UNUSED,
    if (g_main_loop_is_running(ecore_main_loop))
      {
         // only set idling state in dispatch
-        if (ecore_idling && (!_ecore_idler_exist(obj)) &&
-            (!efl_loop_message_exists(obj)))
+        if (ecore_idling && (!_ecore_main_idlers_exist(pd)) &&
+            (!pd->message_queue))
           {
              if (_efl_loop_timers_exists(obj, pd))
                {
@@ -720,7 +737,7 @@ _ecore_main_gsource_prepare(GSource *source EINA_UNUSED,
         else
           {
              *next_time = 0;
-             if (efl_loop_message_exists(obj)) ready = TRUE;
+             if (pd->message_queue) ready = TRUE;
           }
 
         if (pd->fd_handlers_with_prep) _ecore_main_prepare_handlers(obj, pd);
@@ -745,8 +762,8 @@ _ecore_main_gsource_check(GSource *source EINA_UNUSED)
    in_main_loop++;
    pd->in_loop = in_main_loop;
    // check if old timers expired
-   if (ecore_idling && (!_ecore_idler_exist(obj)) &&
-       (!efl_loop_message_exists(obj)))
+   if (ecore_idling && (!_ecore_main_idlers_exist(pd)) &&
+       (!pd->message_queue))
      {
         if (timer_fd >= 0)
           {
@@ -801,9 +818,9 @@ _ecore_main_gsource_dispatch(GSource    *source EINA_UNUSED,
    _efl_loop_timer_enable_new(obj, pd);
    next_time = _efl_loop_timer_next_get(obj, pd);
 
-   events_ready = efl_loop_message_exists(obj);
+   events_ready = pd->message_queue ? 1 : 0;
    timers_ready = _efl_loop_timers_exists(obj, pd) && (0.0 == next_time);
-   idlers_ready = _ecore_idler_exist(obj);
+   idlers_ready = _ecore_main_idlers_exist(pd);
 
    in_main_loop++;
    pd->in_loop = in_main_loop;
@@ -814,21 +831,21 @@ _ecore_main_gsource_dispatch(GSource    *source EINA_UNUSED,
    if (ecore_idling && events_ready)
      {
         _ecore_animator_run_reset();
-        _ecore_idle_exiter_call(obj);
+        efl_event_callback_call(obj, EFL_LOOP_EVENT_IDLE_EXIT, NULL);
         ecore_idling = 0;
      }
    else if (!ecore_idling && !events_ready) ecore_idling = 1;
 
    if (ecore_idling)
      {
-        _ecore_idler_all_call(obj);
+        _ecore_main_idler_all_call(obj);
 
-        events_ready = efl_loop_message_exists(obj);
+        events_ready = pd->message_queue ? 1 : 0;
 
         if (ecore_fds_ready || events_ready || timers_ready)
           {
              _ecore_animator_run_reset();
-             _ecore_idle_exiter_call(obj);
+             efl_event_callback_call(obj, EFL_LOOP_EVENT_IDLE_EXIT, NULL);
              ecore_idling = 0;
           }
      }
@@ -845,7 +862,7 @@ _ecore_main_gsource_dispatch(GSource    *source EINA_UNUSED,
 
         _efl_loop_timer_expired_timers_call(obj, pd, pd->loop_time);
 
-        _ecore_idle_enterer_call(obj);
+        efl_event_callback_call(obj, EFL_LOOP_EVENT_IDLE_ENTER, NULL);
         _ecore_throttle();
         _throttle_do(pd);
         _ecore_glib_idle_enterer_called = TRUE;
@@ -887,7 +904,7 @@ _ecore_main_loop_timer_run(uv_timer_t *timer EINA_UNUSED)
    if (_ecore_main_uv_idling)
      {
         _ecore_main_uv_idling = EINA_FALSE;
-        _ecore_idle_exiter_call(obj);
+        efl_event_callback_call(obj, EFL_LOOP_EVENT_IDLE_EXIT, NULL);
         _ecore_animator_run_reset();
      }
    pd->loop_time = ecore_time_get();
@@ -1161,7 +1178,7 @@ _ecore_main_loop_iterate_may_block(Eo *obj, Efl_Loop_Data *pd, int may_block)
              _ecore_main_loop_iterate_internal(obj, pd, !may_block);
              in_main_loop--;
              pd->in_loop = in_main_loop;
-             return efl_loop_message_exists(obj);
+             return pd->message_queue ? 1 : 0;
 #else
              return g_main_context_iteration(NULL, may_block);
 #endif
@@ -1178,7 +1195,7 @@ _ecore_main_loop_iterate_may_block(Eo *obj, Efl_Loop_Data *pd, int may_block)
         pd->loop_time = ecore_time_get();
         _ecore_main_loop_iterate_internal(obj, pd, !may_block);
         pd->in_loop--;
-        return efl_loop_message_exists(obj);
+        return pd->message_queue ? 1 : 0;
      }
    return 0;
 }
@@ -2275,16 +2292,16 @@ _ecore_main_loop_uv_prepare(uv_prepare_t *handle EINA_UNUSED)
    if (!_ecore_main_uv_idling)
      {
         _ecore_main_uv_idling = EINA_TRUE;
-        _ecore_idle_enterer_call(obj);
+        efl_event_callback_call(obj, EFL_LOOP_EVENT_IDLE_ENTER, NULL);
         _ecore_throttle();
         _throttle_do(pd);
      }
 
    if (_ecore_main_uv_idling)
      {
-        _ecore_idler_all_call(obj);
+        _ecore_main_idler_all_call(obj);
         DBG("called idles");
-        if (_ecore_idler_exist(_obj) || efl_loop_message_exists(obj)) t = 0.0;
+        if (_ecore_main_idlers_exist(pd) || (pd->message_queue)) t = 0.0;
      }
 
    if (pd->do_quit)
@@ -2293,7 +2310,7 @@ _ecore_main_loop_uv_prepare(uv_prepare_t *handle EINA_UNUSED)
 
         if (_ecore_main_uv_idling)
           {
-             _ecore_idle_exiter_call(obj);
+             efl_event_callback_call(obj, EFL_LOOP_EVENT_IDLE_EXIT, NULL);
              _ecore_animator_run_reset();
              _ecore_main_uv_idling = EINA_FALSE;
           }
@@ -2345,13 +2362,12 @@ _ecore_main_loop_spin_core(Eo *obj, Efl_Loop_Data *pd)
    // as we are spinning we need to update loop time per spin
    pd->loop_time = ecore_time_get();
    // call all idlers
-   _ecore_idler_all_call(obj);
+   _ecore_main_idler_all_call(obj);
    // which returns false if no more idelrs exist
-   if (!_ecore_idler_exist(obj)) return SPIN_RESTART;
+   if (!_ecore_main_idlers_exist(pd)) return SPIN_RESTART;
    // sneaky - drop through or if checks - the first one to succeed
    // drops through and returns "continue" so further ones dont run
-   if ((_ecore_main_select(obj, pd, 0.0) > 0) ||
-       (efl_loop_message_exists(obj)) ||
+   if ((_ecore_main_select(obj, pd, 0.0) > 0) || (pd->message_queue) ||
        (_ecore_signal_count_get(obj, pd) > 0) || (pd->do_quit))
      return LOOP_CONTINUE;
    // default - spin more
@@ -2431,10 +2447,10 @@ _ecore_main_loop_iterate_internal(Eo *obj, Efl_Loop_Data *pd, int once_only)
    if (obj == ML_OBJ) _ecore_signal_received_process(obj, pd);
    // if as a result of timers/animators or signals we have accumulated
    // events, then instantly handle them
-   if (efl_loop_message_exists(obj))
+   if (pd->message_queue)
      {
         // but first conceptually enter an idle state
-        _ecore_idle_enterer_call(obj);
+        efl_event_callback_call(obj, EFL_LOOP_EVENT_IDLE_ENTER, NULL);
         _ecore_throttle();
         _throttle_do(pd);
         // now quickly poll to see which input fd's are active
@@ -2461,7 +2477,7 @@ _ecore_main_loop_iterate_internal(Eo *obj, Efl_Loop_Data *pd, int once_only)
    else
      {
         // call idle enterers ...
-        _ecore_idle_enterer_call(obj);
+        efl_event_callback_call(obj, EFL_LOOP_EVENT_IDLE_ENTER, NULL);
         _ecore_throttle();
         _throttle_do(pd);
      }
@@ -2472,7 +2488,7 @@ _ecore_main_loop_iterate_internal(Eo *obj, Efl_Loop_Data *pd, int once_only)
 
    // if there are any (buffered fd handling may generate them)
    // then jump to processing them */
-   if (efl_loop_message_exists(obj))
+   if (pd->message_queue)
      {
         _ecore_main_select(obj, pd, 0.0);
         _efl_loop_timer_enable_new(obj, pd);
@@ -2482,7 +2498,7 @@ _ecore_main_loop_iterate_internal(Eo *obj, Efl_Loop_Data *pd, int once_only)
    if (once_only)
      {
         // in once_only mode enter idle here instead and then return
-        _ecore_idle_enterer_call(obj);
+        efl_event_callback_call(obj, EFL_LOOP_EVENT_IDLE_ENTER, NULL);
         _ecore_throttle();
         _throttle_do(pd);
         _efl_loop_timer_enable_new(obj, pd);
@@ -2509,12 +2525,12 @@ start_loop: //-*************************************************************
         _efl_loop_timer_enable_new(obj, pd);
         goto done;
      }
-   if (!efl_loop_message_exists(obj))
+   if (!pd->message_queue)
      {
         // init flags
         next_time = _efl_loop_timer_next_get(obj, pd);
         // no idlers
-        if (!_ecore_idler_exist(obj))
+        if (!_ecore_main_idlers_exist(pd))
           {
              // sleep until timeout or forever (-1.0) waiting for on fds
              _ecore_main_select(obj, pd, next_time);
@@ -2539,7 +2555,7 @@ process_all: //-*********************************************************
    if (!once_only)
      {
         _ecore_animator_run_reset(); // XXX:
-        _ecore_idle_exiter_call(obj);
+        efl_event_callback_call(obj, EFL_LOOP_EVENT_IDLE_EXIT, NULL);
      }
    // call the fd handler per fd that became alive...
    // this should read or write any data to the monitored fd and then
@@ -2549,13 +2565,13 @@ process_all: //-*********************************************************
    // process signals into events ....
    _ecore_signal_received_process(obj, pd);
    // handle events ...
-   efl_loop_message_process(obj); // XXX: event queue per loop
+   efl_loop_message_process(obj);
    _ecore_main_fd_handlers_cleanup(obj, pd);
 
    if (once_only)
      {
         // if in once_only mode handle idle exiting
-        _ecore_idle_enterer_call(obj);
+        efl_event_callback_call(obj, EFL_LOOP_EVENT_IDLE_ENTER, NULL);
         _ecore_throttle();
         _throttle_do(pd);
      }
index 35e6d48..b194029 100644 (file)
@@ -242,14 +242,6 @@ void        *_ecore_factorized_idle_del(Ecore_Idler *idler);
 void    _ecore_factorized_idle_process(void *data, const Efl_Event *event);
 void    _ecore_factorized_idle_event_del(void *data, const Efl_Event *event);
 
-void         _ecore_idler_all_call(Eo *loop);
-int          _ecore_idler_exist(Eo *loop);
-
-void         _ecore_idle_enterer_call(Eo *loop);
-
-void         _ecore_idle_exiter_call(Eo *loop);
-
-
 Eina_Future_Scheduler *_ecore_event_future_scheduler_get(void);
 
 Eina_Bool    _ecore_event_init(void);
@@ -502,7 +494,6 @@ void ecore_loop_promise_fulfill(Efl_Promise *p);
 #define EFL_LOOP_DATA efl_data_scope_get(efl_loop_main_get(EFL_LOOP_CLASS), EFL_LOOP_CLASS)
 
 EOAPI Eina_Bool efl_loop_message_process(Eo *obj);
-EOAPI Eina_Bool efl_loop_message_exists(Eo *obj);
 
 #undef EAPI
 #define EAPI
index 6cf133f..cf58573 100644 (file)
@@ -657,15 +657,6 @@ _efl_loop_message_process(Eo *obj, Efl_Loop_Data *pd)
 
 EOAPI EFL_FUNC_BODY(efl_loop_message_process, Eina_Bool, 0);
 
-EOLIAN static Eina_Bool
-_efl_loop_message_exists(Eo *obj EINA_UNUSED, Efl_Loop_Data *pd)
-{
-   if (pd->message_queue) return EINA_TRUE;
-   return EINA_FALSE;
-}
-
-EOAPI EFL_FUNC_BODY(efl_loop_message_exists, Eina_Bool, 0);
-
 EWAPI void
 efl_build_version_set(int vmaj, int vmin, int vmic, int revision,
                       const char *flavor, const char *build_id)
@@ -714,7 +705,6 @@ efl_loop_future_scheduler_get(Eo *obj)
 }
 
 #define EFL_LOOP_EXTRA_OPS \
-  EFL_OBJECT_OP_FUNC(efl_loop_message_process, _efl_loop_message_process), \
-  EFL_OBJECT_OP_FUNC(efl_loop_message_exists, _efl_loop_message_exists)
+  EFL_OBJECT_OP_FUNC(efl_loop_message_process, _efl_loop_message_process)
 
 #include "efl_loop.eo.c"