forked from enlightenment/efl
ecore: Fix clean shutdown
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.
This commit is contained in:
parent
b6eeed74bb
commit
9427862d40
|
@ -1021,7 +1021,6 @@ _ecore_main_loop_clear(Eo *obj, Efl_Loop_Data *pd)
|
|||
}
|
||||
#endif
|
||||
}
|
||||
#ifdef HAVE_EPOLL
|
||||
if (pd->epoll_fd >= 0)
|
||||
{
|
||||
close(pd->epoll_fd);
|
||||
|
@ -1032,7 +1031,6 @@ _ecore_main_loop_clear(Eo *obj, Efl_Loop_Data *pd)
|
|||
close(pd->timer_fd);
|
||||
pd->timer_fd = -1;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -1049,9 +1047,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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue