2 * vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2
12 #include "ecore_private.h"
19 int (*func) (void *data);
22 Eina_Bool delete_me : 1;
26 static Ecore_Idler *idlers = NULL;
27 static Ecore_Idler *idler_current = NULL;
28 static int idlers_delete_me = 0;
31 * Add an idler handler.
32 * @param func The function to call when idling.
33 * @param data The data to be passed to this @p func call.
34 * @return A idler handle if successfully added. NULL otherwise.
37 * Add an idler handle to the event loop, returning a handle on success and
38 * NULL otherwise. The function @p func will be called repeatedly while
39 * no other events are ready to be processed, as long as it returns 1
40 * (or ECORE_CALLBACK_RENEW). A return of 0 (or ECORE_CALLBACK_CANCEL) deletes
43 * Idlers are useful for progressively prossessing data without blocking.
46 ecore_idler_add(int (*func) (void *data), const void *data)
50 if (!func) return NULL;
51 ie = calloc(1, sizeof(Ecore_Idler));
53 ECORE_MAGIC_SET(ie, ECORE_MAGIC_IDLER);
55 ie->data = (void *)data;
56 idlers = (Ecore_Idler *) eina_inlist_append(EINA_INLIST_GET(idlers), EINA_INLIST_GET(ie));
61 * Delete an idler callback from the list to be executed.
62 * @param idler The handle of the idler callback to delete
63 * @return The data pointer passed to the idler callback on success. NULL
68 ecore_idler_del(Ecore_Idler *idler)
70 if (!ECORE_MAGIC_CHECK(idler, ECORE_MAGIC_IDLER))
72 ECORE_MAGIC_FAIL(idler, ECORE_MAGIC_IDLER,
82 _ecore_idler_shutdown(void)
87 idlers = (Ecore_Idler *) eina_inlist_remove(EINA_INLIST_GET(idlers), EINA_INLIST_GET(idlers));
88 ECORE_MAGIC_SET(ie, ECORE_MAGIC_NONE);
96 _ecore_idler_call(void)
100 /* regular main loop, start from head */
101 idler_current = idlers;
105 /* recursive main loop, continue from where we were */
106 idler_current = (Ecore_Idler *)EINA_INLIST_GET(idler_current)->next;
109 while (idler_current)
111 Ecore_Idler *ie = (Ecore_Idler *)idler_current;
115 if (!ie->func(ie->data)) 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;