summaryrefslogtreecommitdiff
path: root/legacy/ecore/src/lib/ecore/ecore_poll.c
diff options
context:
space:
mode:
authorCarsten Haitzler <raster@rasterman.com>2011-10-21 05:40:39 +0000
committerCarsten Haitzler <raster@rasterman.com>2011-10-21 05:40:39 +0000
commit58cbf16625119b70e515d212861e499082c1221d (patch)
tree3b1b802fb7bfb4c53ac446acb5dc799097f07f95 /legacy/ecore/src/lib/ecore/ecore_poll.c
parent8893a9ff35f58e012be3cc838bd94268add13e10 (diff)
ran ecrustify on ecore. some manual fixing too.
SVN revision: 64238
Diffstat (limited to '')
-rw-r--r--legacy/ecore/src/lib/ecore/ecore_poll.c161
1 files changed, 82 insertions, 79 deletions
diff --git a/legacy/ecore/src/lib/ecore/ecore_poll.c b/legacy/ecore/src/lib/ecore/ecore_poll.c
index cc0ada6160..a283cb51c5 100644
--- a/legacy/ecore/src/lib/ecore/ecore_poll.c
+++ b/legacy/ecore/src/lib/ecore/ecore_poll.c
@@ -7,40 +7,38 @@
7#include "Ecore.h" 7#include "Ecore.h"
8#include "ecore_private.h" 8#include "ecore_private.h"
9 9
10
11struct _Ecore_Poller 10struct _Ecore_Poller
12{ 11{
13 EINA_INLIST; 12 EINA_INLIST;
14 ECORE_MAGIC; 13 ECORE_MAGIC;
15 int ibit; 14 int ibit;
16 unsigned char delete_me : 1; 15 unsigned char delete_me : 1;
17 Ecore_Task_Cb func; 16 Ecore_Task_Cb func;
18 void *data; 17 void *data;
19}; 18};
20 19
21 20static Ecore_Timer *timer = NULL;
22static Ecore_Timer *timer = NULL; 21static int min_interval = -1;
23static int min_interval = -1; 22static int interval_incr = 0;
24static int interval_incr = 0; 23static int at_tick = 0;
25static int at_tick = 0; 24static int just_added_poller = 0;
26static int just_added_poller = 0; 25static int poller_delete_count = 0;
27static int poller_delete_count = 0; 26static int poller_walking = 0;
28static int poller_walking = 0; 27static double poll_interval = 0.125;
29static double poll_interval = 0.125; 28static double poll_cur_interval = 0.0;
30static double poll_cur_interval = 0.0; 29static double last_tick = 0.0;
31static double last_tick = 0.0; 30static Ecore_Poller *pollers[16] =
32static Ecore_Poller *pollers[16] =
33{ 31{
34 NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL, 32 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
35 NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL 33 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
36}; 34};
37static unsigned short poller_counters[16] = 35static unsigned short poller_counters[16] =
38{ 36{
39 0,0,0,0,0,0,0,0, 37 0, 0, 0, 0, 0, 0, 0, 0,
40 0,0,0,0,0,0,0,0 38 0, 0, 0, 0, 0, 0, 0, 0
41}; 39};
42 40
43static void _ecore_poller_next_tick_eval(void); 41static void _ecore_poller_next_tick_eval(void);
44static Eina_Bool _ecore_poller_cb_timer(void *data); 42static Eina_Bool _ecore_poller_cb_timer(void *data);
45 43
46static void 44static void
@@ -61,12 +59,12 @@ _ecore_poller_next_tick_eval(void)
61 if (min_interval < 0) 59 if (min_interval < 0)
62 { 60 {
63 /* no pollers */ 61 /* no pollers */
64 if (timer) 62 if (timer)
65 { 63 {
66 ecore_timer_del(timer); 64 ecore_timer_del(timer);
67 timer = NULL; 65 timer = NULL;
68 } 66 }
69 return; 67 return;
70 } 68 }
71 interval_incr = (1 << min_interval); 69 interval_incr = (1 << min_interval);
72 interval = interval_incr * poll_interval; 70 interval = interval_incr * poll_interval;
@@ -91,8 +89,8 @@ _ecore_poller_next_tick_eval(void)
91 if (interval != poll_cur_interval) 89 if (interval != poll_cur_interval)
92 { 90 {
93 t -= last_tick; /* time since we last ticked */ 91 t -= last_tick; /* time since we last ticked */
94 /* delete the timer and reset it to tick off in the new 92 /* delete the timer and reset it to tick off in the new
95 * time interval. at the tick this will be adjusted */ 93 * time interval. at the tick this will be adjusted */
96 ecore_timer_del(timer); 94 ecore_timer_del(timer);
97 timer = ecore_timer_add(interval - t, 95 timer = ecore_timer_add(interval - t,
98 _ecore_poller_cb_timer, NULL); 96 _ecore_poller_cb_timer, NULL);
@@ -128,23 +126,23 @@ _ecore_poller_cb_timer(void *data __UNUSED__)
128 { 126 {
129 /* if the counter is @ 0 - this means that counter "went off" this 127 /* if the counter is @ 0 - this means that counter "went off" this
130 * tick interval, so run all pollers hooked to that counter */ 128 * tick interval, so run all pollers hooked to that counter */
131 if (poller_counters[i] == 0) 129 if (poller_counters[i] == 0)
132 { 130 {
133 EINA_INLIST_FOREACH(pollers[i], poller) 131 EINA_INLIST_FOREACH(pollers[i], poller)
134 { 132 {
135 if (!poller->delete_me) 133 if (!poller->delete_me)
136 { 134 {
137 if (!poller->func(poller->data)) 135 if (!poller->func(poller->data))
138 { 136 {
139 if (!poller->delete_me) 137 if (!poller->delete_me)
140 { 138 {
141 poller->delete_me = 1; 139 poller->delete_me = 1;
142 poller_delete_count++; 140 poller_delete_count++;
143 } 141 }
144 } 142 }
145 } 143 }
146 } 144 }
147 } 145 }
148 } 146 }
149 poller_walking--; 147 poller_walking--;
150 148
@@ -152,23 +150,23 @@ _ecore_poller_cb_timer(void *data __UNUSED__)
152 if (poller_delete_count > 0) 150 if (poller_delete_count > 0)
153 { 151 {
154 /* FIXME: walk all pollers and remove deleted ones */ 152 /* FIXME: walk all pollers and remove deleted ones */
155 for (i = 0; i < 15; i++) 153 for (i = 0; i < 15; i++)
156 { 154 {
157 for (l = pollers[i]; l;) 155 for (l = pollers[i]; l; )
158 { 156 {
159 poller = l; 157 poller = l;
160 l = (Ecore_Poller *) EINA_INLIST_GET(l)->next; 158 l = (Ecore_Poller *)EINA_INLIST_GET(l)->next;
161 if (poller->delete_me) 159 if (poller->delete_me)
162 { 160 {
163 pollers[i] = (Ecore_Poller *) eina_inlist_remove(EINA_INLIST_GET(pollers[i]), EINA_INLIST_GET(poller)); 161 pollers[i] = (Ecore_Poller *)eina_inlist_remove(EINA_INLIST_GET(pollers[i]), EINA_INLIST_GET(poller));
164 free(poller); 162 free(poller);
165 poller_delete_count--; 163 poller_delete_count--;
166 changes++; 164 changes++;
167 if (poller_delete_count <= 0) break; 165 if (poller_delete_count <= 0) break;
168 } 166 }
169 } 167 }
170 if (poller_delete_count <= 0) break; 168 if (poller_delete_count <= 0) break;
171 } 169 }
172 } 170 }
173 /* if we deleted or added any pollers, then we need to re-evaluate our 171 /* if we deleted or added any pollers, then we need to re-evaluate our
174 * minimum poll interval */ 172 * minimum poll interval */
@@ -196,7 +194,6 @@ _ecore_poller_cb_timer(void *data __UNUSED__)
196 * @{ 194 * @{
197 */ 195 */
198 196
199
200/** 197/**
201 * Sets the time between ticks (in seconds) for the given ticker clock. 198 * Sets the time between ticks (in seconds) for the given ticker clock.
202 * @param type The ticker type to adjust 199 * @param type The ticker type to adjust
@@ -206,7 +203,8 @@ _ecore_poller_cb_timer(void *data __UNUSED__)
206 * by @p type to the time period defined by @p poll_time. 203 * by @p type to the time period defined by @p poll_time.
207 */ 204 */
208EAPI void 205EAPI void
209ecore_poller_poll_interval_set(Ecore_Poller_Type type __UNUSED__, double poll_time) 206ecore_poller_poll_interval_set(Ecore_Poller_Type type __UNUSED__,
207 double poll_time)
210{ 208{
211 poll_interval = poll_time; 209 poll_interval = poll_time;
212 _ecore_poller_next_tick_eval(); 210 _ecore_poller_next_tick_eval();
@@ -272,7 +270,10 @@ ecore_poller_poll_interval_get(Ecore_Poller_Type type __UNUSED__)
272 * invalid. 270 * invalid.
273 */ 271 */
274EAPI Ecore_Poller * 272EAPI Ecore_Poller *
275ecore_poller_add(Ecore_Poller_Type type __UNUSED__, int interval, Ecore_Task_Cb func, const void *data) 273ecore_poller_add(Ecore_Poller_Type type __UNUSED__,
274 int interval,
275 Ecore_Task_Cb func,
276 const void *data)
276{ 277{
277 Ecore_Poller *poller; 278 Ecore_Poller *poller;
278 int ibit; 279 int ibit;
@@ -297,7 +298,7 @@ ecore_poller_add(Ecore_Poller_Type type __UNUSED__, int interval, Ecore_Task_Cb
297 poller->ibit = ibit; 298 poller->ibit = ibit;
298 poller->func = func; 299 poller->func = func;
299 poller->data = (void *)data; 300 poller->data = (void *)data;
300 pollers[poller->ibit] = (Ecore_Poller *) eina_inlist_prepend(EINA_INLIST_GET(pollers[poller->ibit]), EINA_INLIST_GET(poller)); 301 pollers[poller->ibit] = (Ecore_Poller *)eina_inlist_prepend(EINA_INLIST_GET(pollers[poller->ibit]), EINA_INLIST_GET(poller));
301 if (poller_walking) 302 if (poller_walking)
302 just_added_poller++; 303 just_added_poller++;
303 else 304 else
@@ -316,14 +317,15 @@ ecore_poller_add(Ecore_Poller_Type type __UNUSED__, int interval, Ecore_Task_Cb
316 * a poll rate without deleting and re-creating a poller. 317 * a poll rate without deleting and re-creating a poller.
317 */ 318 */
318EAPI Eina_Bool 319EAPI Eina_Bool
319ecore_poller_poller_interval_set(Ecore_Poller *poller, int interval) 320ecore_poller_poller_interval_set(Ecore_Poller *poller,
321 int interval)
320{ 322{
321 int ibit; 323 int ibit;
322 324
323 if (!ECORE_MAGIC_CHECK(poller, ECORE_MAGIC_POLLER)) 325 if (!ECORE_MAGIC_CHECK(poller, ECORE_MAGIC_POLLER))
324 { 326 {
325 ECORE_MAGIC_FAIL(poller, ECORE_MAGIC_POLLER, 327 ECORE_MAGIC_FAIL(poller, ECORE_MAGIC_POLLER,
326 "ecore_poller_poller_interval_set"); 328 "ecore_poller_poller_interval_set");
327 return EINA_FALSE; 329 return EINA_FALSE;
328 } 330 }
329 331
@@ -332,17 +334,17 @@ ecore_poller_poller_interval_set(Ecore_Poller *poller, int interval)
332 ibit = -1; 334 ibit = -1;
333 while (interval != 0) 335 while (interval != 0)
334 { 336 {
335 ibit++; 337 ibit++;
336 interval >>= 1; 338 interval >>= 1;
337 } 339 }
338 /* only allow up to 32768 - i.e. ibit == 15, so limit it */ 340 /* only allow up to 32768 - i.e. ibit == 15, so limit it */
339 if (ibit > 15) ibit = 15; 341 if (ibit > 15) ibit = 15;
340 /* if interval specified is the same as interval set, return true without wasting time */ 342 /* if interval specified is the same as interval set, return true without wasting time */
341 if (poller->ibit == ibit) 343 if (poller->ibit == ibit)
342 return EINA_TRUE; 344 return EINA_TRUE;
343 pollers[poller->ibit] = (Ecore_Poller *) eina_inlist_remove(EINA_INLIST_GET(pollers[poller->ibit]), EINA_INLIST_GET(poller)); 345 pollers[poller->ibit] = (Ecore_Poller *)eina_inlist_remove(EINA_INLIST_GET(pollers[poller->ibit]), EINA_INLIST_GET(poller));
344 poller->ibit = ibit; 346 poller->ibit = ibit;
345 pollers[poller->ibit] = (Ecore_Poller *) eina_inlist_prepend(EINA_INLIST_GET(pollers[poller->ibit]), EINA_INLIST_GET(poller)); 347 pollers[poller->ibit] = (Ecore_Poller *)eina_inlist_prepend(EINA_INLIST_GET(pollers[poller->ibit]), EINA_INLIST_GET(poller));
346 if (poller_walking) 348 if (poller_walking)
347 just_added_poller++; 349 just_added_poller++;
348 else 350 else
@@ -366,15 +368,15 @@ ecore_poller_poller_interval_get(Ecore_Poller *poller)
366 if (!ECORE_MAGIC_CHECK(poller, ECORE_MAGIC_POLLER)) 368 if (!ECORE_MAGIC_CHECK(poller, ECORE_MAGIC_POLLER))
367 { 369 {
368 ECORE_MAGIC_FAIL(poller, ECORE_MAGIC_POLLER, 370 ECORE_MAGIC_FAIL(poller, ECORE_MAGIC_POLLER,
369 "ecore_poller_poller_interval_get"); 371 "ecore_poller_poller_interval_get");
370 return 0; 372 return 0;
371 } 373 }
372 374
373 ibit = poller->ibit; 375 ibit = poller->ibit;
374 while (ibit != 0) 376 while (ibit != 0)
375 { 377 {
376 ibit--; 378 ibit--;
377 interval <<= 1; 379 interval <<= 1;
378 } 380 }
379 return interval; 381 return interval;
380} 382}
@@ -396,7 +398,7 @@ ecore_poller_del(Ecore_Poller *poller)
396 if (!ECORE_MAGIC_CHECK(poller, ECORE_MAGIC_POLLER)) 398 if (!ECORE_MAGIC_CHECK(poller, ECORE_MAGIC_POLLER))
397 { 399 {
398 ECORE_MAGIC_FAIL(poller, ECORE_MAGIC_POLLER, 400 ECORE_MAGIC_FAIL(poller, ECORE_MAGIC_POLLER,
399 "ecore_poller_del"); 401 "ecore_poller_del");
400 return NULL; 402 return NULL;
401 } 403 }
402 /* we are walking the poller list - a bad idea to remove from it while 404 /* we are walking the poller list - a bad idea to remove from it while
@@ -410,7 +412,7 @@ ecore_poller_del(Ecore_Poller *poller)
410 } 412 }
411 /* not in loop so safe - delete immediately */ 413 /* not in loop so safe - delete immediately */
412 data = poller->data; 414 data = poller->data;
413 pollers[poller->ibit] = (Ecore_Poller *) eina_inlist_remove(EINA_INLIST_GET(pollers[poller->ibit]), EINA_INLIST_GET(poller)); 415 pollers[poller->ibit] = (Ecore_Poller *)eina_inlist_remove(EINA_INLIST_GET(pollers[poller->ibit]), EINA_INLIST_GET(poller));
414 free(poller); 416 free(poller);
415 _ecore_poller_next_tick_eval(); 417 _ecore_poller_next_tick_eval();
416 return data; 418 return data;
@@ -430,8 +432,9 @@ _ecore_poller_shutdown(void)
430 { 432 {
431 while ((poller = pollers[i])) 433 while ((poller = pollers[i]))
432 { 434 {
433 pollers[i] = (Ecore_Poller *) eina_inlist_remove(EINA_INLIST_GET(pollers[i]), EINA_INLIST_GET(pollers[i])); 435 pollers[i] = (Ecore_Poller *)eina_inlist_remove(EINA_INLIST_GET(pollers[i]), EINA_INLIST_GET(pollers[i]));
434 free(poller); 436 free(poller);
435 } 437 }
436 } 438 }
437} 439}
440