8 #include "ecore_private.h"
18 Eina_Bool delete_me : 1;
22 static Ecore_Idler *idlers = NULL;
23 static Ecore_Idler *idler_current = NULL;
24 static int idlers_delete_me = 0;
27 * Add an idler handler.
28 * @param func The function to call when idling.
29 * @param data The data to be passed to this @p func call.
30 * @return A idler handle if successfully added. NULL otherwise.
33 * Add an idler handle to the event loop, returning a handle on success and
34 * NULL otherwise. The function @p func will be called repeatedly while
35 * no other events are ready to be processed, as long as it returns 1
36 * (or ECORE_CALLBACK_RENEW). A return of 0 (or ECORE_CALLBACK_CANCEL) deletes
39 * Idlers are useful for progressively prossessing data without blocking.
42 ecore_idler_add(Ecore_Task_Cb func, const void *data)
46 if (!func) return NULL;
47 ie = calloc(1, sizeof(Ecore_Idler));
49 ECORE_MAGIC_SET(ie, ECORE_MAGIC_IDLER);
51 ie->data = (void *)data;
52 idlers = (Ecore_Idler *) eina_inlist_append(EINA_INLIST_GET(idlers), EINA_INLIST_GET(ie));
57 * Delete an idler callback from the list to be executed.
58 * @param idler The handle of the idler callback to delete
59 * @return The data pointer passed to the idler callback on success. NULL
64 ecore_idler_del(Ecore_Idler *idler)
66 if (!ECORE_MAGIC_CHECK(idler, ECORE_MAGIC_IDLER))
68 ECORE_MAGIC_FAIL(idler, ECORE_MAGIC_IDLER,
72 EINA_SAFETY_ON_TRUE_RETURN_VAL(idler->delete_me, NULL);
79 _ecore_idler_shutdown(void)
84 idlers = (Ecore_Idler *) eina_inlist_remove(EINA_INLIST_GET(idlers), EINA_INLIST_GET(idlers));
85 ECORE_MAGIC_SET(ie, ECORE_MAGIC_NONE);
93 _ecore_idler_call(void)
97 /* regular main loop, start from head */
98 idler_current = idlers;
102 /* recursive main loop, continue from where we were */
103 idler_current = (Ecore_Idler *)EINA_INLIST_GET(idler_current)->next;
106 while (idler_current)
108 Ecore_Idler *ie = (Ecore_Idler *)idler_current;
112 if (!ie->func(ie->data))
114 if (!ie->delete_me) ecore_idler_del(ie);
118 if (idler_current) /* may have changed in recursive main loops */
119 idler_current = (Ecore_Idler *)EINA_INLIST_GET(idler_current)->next;
121 if (idlers_delete_me)
124 int deleted_idlers_in_use = 0;
128 l = (Ecore_Idler *) EINA_INLIST_GET(l)->next;
133 deleted_idlers_in_use++;
137 idlers = (Ecore_Idler *) eina_inlist_remove(EINA_INLIST_GET(idlers), EINA_INLIST_GET(ie));
138 ECORE_MAGIC_SET(ie, ECORE_MAGIC_NONE);
142 if (!deleted_idlers_in_use)
143 idlers_delete_me = 0;
145 if (idlers) return 1;
150 _ecore_idler_exist(void)
152 if (idlers) return 1;