diff options
Diffstat (limited to 'libraries/ecore/src/lib/ecore/ecore_timer.c')
-rw-r--r-- | libraries/ecore/src/lib/ecore/ecore_timer.c | 46 |
1 files changed, 39 insertions, 7 deletions
diff --git a/libraries/ecore/src/lib/ecore/ecore_timer.c b/libraries/ecore/src/lib/ecore/ecore_timer.c index 9c66545..cc19e3f 100644 --- a/libraries/ecore/src/lib/ecore/ecore_timer.c +++ b/libraries/ecore/src/lib/ecore/ecore_timer.c | |||
@@ -35,6 +35,7 @@ struct _Ecore_Timer | |||
35 | unsigned char just_added : 1; | 35 | unsigned char just_added : 1; |
36 | unsigned char frozen : 1; | 36 | unsigned char frozen : 1; |
37 | }; | 37 | }; |
38 | GENERIC_ALLOC_SIZE_DECLARE(Ecore_Timer); | ||
38 | 39 | ||
39 | static void _ecore_timer_set(Ecore_Timer *timer, | 40 | static void _ecore_timer_set(Ecore_Timer *timer, |
40 | double at, | 41 | double at, |
@@ -140,7 +141,7 @@ ecore_timer_add(double in, | |||
140 | _ecore_lock(); | 141 | _ecore_lock(); |
141 | if (!func) goto unlock; | 142 | if (!func) goto unlock; |
142 | if (in < 0.0) in = 0.0; | 143 | if (in < 0.0) in = 0.0; |
143 | timer = calloc(1, sizeof(Ecore_Timer)); | 144 | timer = ecore_timer_calloc(1); |
144 | if (!timer) goto unlock; | 145 | if (!timer) goto unlock; |
145 | ECORE_MAGIC_SET(timer, ECORE_MAGIC_TIMER); | 146 | ECORE_MAGIC_SET(timer, ECORE_MAGIC_TIMER); |
146 | now = ecore_time_get(); | 147 | now = ecore_time_get(); |
@@ -287,6 +288,37 @@ ecore_timer_delay(Ecore_Timer *timer, | |||
287 | } | 288 | } |
288 | 289 | ||
289 | /** | 290 | /** |
291 | * Reset a timer to its full interval | ||
292 | * This doesn't affect the interval of a timer | ||
293 | * @param timer The timer | ||
294 | * @since 1.2 | ||
295 | * @note This is equivalent to (but faster than) | ||
296 | * @code | ||
297 | * ecore_timer_delay(timer, ecore_timer_interval_get(timer) - ecore_timer_pending_get(timer)); | ||
298 | * @endcode | ||
299 | */ | ||
300 | EAPI void | ||
301 | ecore_timer_reset(Ecore_Timer *timer) | ||
302 | { | ||
303 | double now, add; | ||
304 | if (!ECORE_MAGIC_CHECK(timer, ECORE_MAGIC_TIMER)) | ||
305 | { | ||
306 | ECORE_MAGIC_FAIL(timer, ECORE_MAGIC_TIMER, | ||
307 | __func__); | ||
308 | return; | ||
309 | } | ||
310 | _ecore_lock(); | ||
311 | now = ecore_time_get(); | ||
312 | |||
313 | if (timer->frozen) | ||
314 | add = timer->pending; | ||
315 | else | ||
316 | add = timer->at - now; | ||
317 | _ecore_timer_delay(timer, timer->in - add); | ||
318 | _ecore_unlock(); | ||
319 | } | ||
320 | |||
321 | /** | ||
290 | * Get the pending time regarding a timer. | 322 | * Get the pending time regarding a timer. |
291 | * | 323 | * |
292 | * @param timer The timer to learn from. | 324 | * @param timer The timer to learn from. |
@@ -470,7 +502,7 @@ _ecore_timer_loop_add(double in, | |||
470 | 502 | ||
471 | if (!func) return timer; | 503 | if (!func) return timer; |
472 | if (in < 0.0) in = 0.0; | 504 | if (in < 0.0) in = 0.0; |
473 | timer = calloc(1, sizeof(Ecore_Timer)); | 505 | timer = ecore_timer_calloc(1); |
474 | if (!timer) return timer; | 506 | if (!timer) return timer; |
475 | ECORE_MAGIC_SET(timer, ECORE_MAGIC_TIMER); | 507 | ECORE_MAGIC_SET(timer, ECORE_MAGIC_TIMER); |
476 | now = ecore_loop_time_get(); | 508 | now = ecore_loop_time_get(); |
@@ -510,7 +542,7 @@ _ecore_timer_del(Ecore_Timer *timer) | |||
510 | if (timer->delete_me) | 542 | if (timer->delete_me) |
511 | timers_delete_me--; | 543 | timers_delete_me--; |
512 | 544 | ||
513 | free(timer); | 545 | ecore_timer_mp_free(timer); |
514 | return data; | 546 | return data; |
515 | } | 547 | } |
516 | 548 | ||
@@ -529,14 +561,14 @@ _ecore_timer_shutdown(void) | |||
529 | { | 561 | { |
530 | timers = (Ecore_Timer *)eina_inlist_remove(EINA_INLIST_GET(timers), EINA_INLIST_GET(timers)); | 562 | timers = (Ecore_Timer *)eina_inlist_remove(EINA_INLIST_GET(timers), EINA_INLIST_GET(timers)); |
531 | ECORE_MAGIC_SET(timer, ECORE_MAGIC_NONE); | 563 | ECORE_MAGIC_SET(timer, ECORE_MAGIC_NONE); |
532 | free(timer); | 564 | ecore_timer_mp_free(timer); |
533 | } | 565 | } |
534 | 566 | ||
535 | while ((timer = suspended)) | 567 | while ((timer = suspended)) |
536 | { | 568 | { |
537 | suspended = (Ecore_Timer *)eina_inlist_remove(EINA_INLIST_GET(suspended), EINA_INLIST_GET(suspended)); | 569 | suspended = (Ecore_Timer *)eina_inlist_remove(EINA_INLIST_GET(suspended), EINA_INLIST_GET(suspended)); |
538 | ECORE_MAGIC_SET(timer, ECORE_MAGIC_NONE); | 570 | ECORE_MAGIC_SET(timer, ECORE_MAGIC_NONE); |
539 | free(timer); | 571 | ecore_timer_mp_free(timer); |
540 | } | 572 | } |
541 | 573 | ||
542 | timer_current = NULL; | 574 | timer_current = NULL; |
@@ -563,7 +595,7 @@ _ecore_timer_cleanup(void) | |||
563 | } | 595 | } |
564 | timers = (Ecore_Timer *)eina_inlist_remove(EINA_INLIST_GET(timers), EINA_INLIST_GET(timer)); | 596 | timers = (Ecore_Timer *)eina_inlist_remove(EINA_INLIST_GET(timers), EINA_INLIST_GET(timer)); |
565 | ECORE_MAGIC_SET(timer, ECORE_MAGIC_NONE); | 597 | ECORE_MAGIC_SET(timer, ECORE_MAGIC_NONE); |
566 | free(timer); | 598 | ecore_timer_mp_free(timer); |
567 | timers_delete_me--; | 599 | timers_delete_me--; |
568 | done++; | 600 | done++; |
569 | if (timers_delete_me == 0) return; | 601 | if (timers_delete_me == 0) return; |
@@ -583,7 +615,7 @@ _ecore_timer_cleanup(void) | |||
583 | } | 615 | } |
584 | suspended = (Ecore_Timer *)eina_inlist_remove(EINA_INLIST_GET(suspended), EINA_INLIST_GET(timer)); | 616 | suspended = (Ecore_Timer *)eina_inlist_remove(EINA_INLIST_GET(suspended), EINA_INLIST_GET(timer)); |
585 | ECORE_MAGIC_SET(timer, ECORE_MAGIC_NONE); | 617 | ECORE_MAGIC_SET(timer, ECORE_MAGIC_NONE); |
586 | free(timer); | 618 | ecore_timer_mp_free(timer); |
587 | timers_delete_me--; | 619 | timers_delete_me--; |
588 | done++; | 620 | done++; |
589 | if (timers_delete_me == 0) return; | 621 | if (timers_delete_me == 0) return; |