8 #include "ecore_private.h"
17 Eina_Bool delete_me : 1;
19 GENERIC_ALLOC_SIZE_DECLARE(Ecore_Idler);
21 static Ecore_Idler *idlers = NULL;
22 static Ecore_Idler *idler_current = NULL;
23 static int idlers_delete_me = 0;
26 _ecore_idler_del(Ecore_Idler *idler);
29 ecore_idler_add(Ecore_Task_Cb func,
32 Ecore_Idler *ie = NULL;
34 EINA_MAIN_LOOP_CHECK_RETURN_VAL(NULL);
36 if (!func) goto unlock;
37 ie = ecore_idler_calloc(1);
39 ECORE_MAGIC_SET(ie, ECORE_MAGIC_IDLER);
41 ie->data = (void *)data;
42 idlers = (Ecore_Idler *)eina_inlist_append(EINA_INLIST_GET(idlers), EINA_INLIST_GET(ie));
49 ecore_idler_del(Ecore_Idler *idler)
53 EINA_MAIN_LOOP_CHECK_RETURN_VAL(NULL);
54 if (!ECORE_MAGIC_CHECK(idler, ECORE_MAGIC_IDLER))
56 ECORE_MAGIC_FAIL(idler, ECORE_MAGIC_IDLER,
62 data = _ecore_idler_del(idler);
76 _ecore_idler_del(Ecore_Idler *idler)
78 EINA_SAFETY_ON_TRUE_RETURN_VAL(idler->delete_me, NULL);
85 _ecore_idler_shutdown(void)
90 idlers = (Ecore_Idler *)eina_inlist_remove(EINA_INLIST_GET(idlers), EINA_INLIST_GET(idlers));
91 ECORE_MAGIC_SET(ie, ECORE_MAGIC_NONE);
92 ecore_idler_mp_free(ie);
99 _ecore_idler_all_call(void)
103 /* regular main loop, start from head */
104 idler_current = idlers;
108 /* recursive main loop, continue from where we were */
109 idler_current = (Ecore_Idler *)EINA_INLIST_GET(idler_current)->next;
112 while (idler_current)
114 Ecore_Idler *ie = (Ecore_Idler *)idler_current;
118 if (!_ecore_call_task_cb(ie->func, ie->data))
120 if (!ie->delete_me) _ecore_idler_del(ie);
124 if (idler_current) /* may have changed in recursive main loops */
125 idler_current = (Ecore_Idler *)EINA_INLIST_GET(idler_current)->next;
127 if (idlers_delete_me)
130 int deleted_idlers_in_use = 0;
131 for (l = idlers; l; )
134 l = (Ecore_Idler *)EINA_INLIST_GET(l)->next;
139 deleted_idlers_in_use++;
143 idlers = (Ecore_Idler *)eina_inlist_remove(EINA_INLIST_GET(idlers), EINA_INLIST_GET(ie));
144 ECORE_MAGIC_SET(ie, ECORE_MAGIC_NONE);
145 ecore_idler_mp_free(ie);
148 if (!deleted_idlers_in_use)
149 idlers_delete_me = 0;
151 if (idlers) return 1;
156 _ecore_idler_exist(void)
158 if (idlers) return 1;