ecore: Fix clean shutdown
authorJean-Philippe Andre <jp.andre@samsung.com>
Fri, 15 Dec 2017 08:42:08 +0000 (17:42 +0900)
committerWonki Kim <wonki_.kim@samsung.com>
Wed, 10 Jan 2018 11:08:13 +0000 (20:08 +0900)
There is no good reason to not shutdown a library properly. The loop
object can easily be deleted safely, if it is properly initialized. The
del event happens before destruction so it is too early to set the
singleton variable to NULL. Do that as late as possible and all calls to
efl_loop_main_get() will work as expected.

The issue with fd's was simply that they were not initialized to -1
(timer_fd), as some #ifdef statements have disappeared.

src/lib/ecore/ecore_main.c
src/lib/ecore/efl_loop.c

index 31cd24d..b512194 100644 (file)
@@ -1086,7 +1086,6 @@ _ecore_main_loop_clear(Eo *obj, Efl_Loop_Data *pd)
           }
 #endif
      }
-#ifdef HAVE_EPOLL
    if (pd->epoll_fd >= 0)
      {
         close(pd->epoll_fd);
@@ -1097,7 +1096,6 @@ _ecore_main_loop_clear(Eo *obj, Efl_Loop_Data *pd)
         close(pd->timer_fd);
         pd->timer_fd = -1;
      }
-#endif
 }
 
 void
@@ -1114,9 +1112,7 @@ _ecore_main_loop_shutdown(void)
    if (!ML_OBJ) return;
    _ecore_main_loop_clear(ML_OBJ, ML_DAT);
 // XXX: this seemingly closes fd's it shouldn't.... :( fd 0?
-//   efl_del(ML_OBJ);
-   ML_OBJ = NULL;
-   ML_DAT = NULL;
+   efl_del(ML_OBJ);
 }
 
 void
index 09ea62a..1cd808d 100644 (file)
@@ -51,25 +51,12 @@ Efl_Version _app_efl_version = { 0, 0, 0, 0, NULL, NULL };
 Eo            *_mainloop_singleton = NULL;
 Efl_Loop_Data *_mainloop_singleton_data = NULL;
 
-static void
-_mainloop_singleton_cb_del(void *data EINA_UNUSED, const Efl_Event *event EINA_UNUSED)
-{
-   _mainloop_singleton = NULL;
-   _mainloop_singleton_data = NULL;
-}
-
-EFL_CALLBACKS_ARRAY_DEFINE(_mainloop_singleton_callbacks,
-                           { EFL_EVENT_DEL, _mainloop_singleton_cb_del });
-
 EOLIAN static Efl_Loop *
 _efl_loop_main_get(Efl_Class *klass EINA_UNUSED, void *_pd EINA_UNUSED)
 {
    if (_mainloop_singleton) return _mainloop_singleton;
    _mainloop_singleton = efl_add(EFL_LOOP_CLASS, NULL);
-   _mainloop_singleton_data = efl_data_scope_get(_mainloop_singleton,
-                                                 EFL_LOOP_CLASS);
-   efl_event_callback_array_add(_mainloop_singleton,
-                                _mainloop_singleton_callbacks(), NULL);
+   _mainloop_singleton_data = efl_data_scope_get(_mainloop_singleton, EFL_LOOP_CLASS);
    return _mainloop_singleton;
 }
 
@@ -318,12 +305,8 @@ _efl_loop_efl_object_constructor(Eo *obj, Efl_Loop_Data *pd)
    pd->loop_time = ecore_time_get();
    pd->providers = eina_hash_pointer_new(EINA_FREE_CB(efl_unref));
    pd->message_handlers = eina_inarray_new(sizeof(Message_Handler), 32);
-#ifdef HAVE_EPOLL
    pd->epoll_fd = -1;
-#endif
-#ifdef USE_G_MAIN_LOOP
    pd->timer_fd = -1;
-#endif
    return obj;
 }
 
@@ -346,6 +329,12 @@ _efl_loop_efl_object_destructor(Eo *obj, Efl_Loop_Data *pd)
    pd->message_handlers = NULL;
 
    efl_destructor(efl_super(obj, EFL_LOOP_CLASS));
+
+   if (obj == _mainloop_singleton)
+     {
+        _mainloop_singleton = NULL;
+        _mainloop_singleton_data = NULL;
+     }
 }
 
 static void