aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCedric BAIL <cedric@osg.samsung.com>2017-02-02 16:52:10 -0800
committerCedric BAIL <cedric@osg.samsung.com>2017-02-02 16:56:57 -0800
commitf66559a4cdab235995c1be6b1e92d2f76e4d11de (patch)
tree1caa4e4abad47f0e64d7429cd4c3c4c53d05e1a5
parentCpumonitor theme - Set an aspect preference other than both so we can properl... (diff)
downloadefl-f66559a4cdab235995c1be6b1e92d2f76e4d11de.tar.gz
ecore: avoid calling ecore_time_get everytime we create a timer.
This is particularly useful for ecore_timer_loop_add which are not supposed to trigger any syscall. It does add a new requirement on the EFL_LOOP_TIME_CLASS to always have an interval defined during construction.
-rw-r--r--src/lib/ecore/ecore_timer.c35
1 files changed, 31 insertions, 4 deletions
diff --git a/src/lib/ecore/ecore_timer.c b/src/lib/ecore/ecore_timer.c
index e83c7e3559..0bf770c7a5 100644
--- a/src/lib/ecore/ecore_timer.c
+++ b/src/lib/ecore/ecore_timer.c
@@ -125,16 +125,20 @@ _efl_loop_timer_efl_object_constructor(Eo *obj, Efl_Loop_Timer_Data *timer)
efl_wref_add(obj, &timer->object);
- timer->at = ecore_time_get();
timer->initialized = 0;
return obj;
}
-
EOLIAN static Eo *
_efl_loop_timer_efl_object_finalize(Eo *obj, Efl_Loop_Timer_Data *pd)
{
+ if (!pd->initialized)
+ {
+ ERR("Timer has not been initialized during construction as mandated.");
+ return NULL;
+ }
+
_efl_loop_timer_util_instanciate(pd);
return efl_finalize(efl_super(obj, MY_CLASS));
@@ -259,7 +263,10 @@ _efl_loop_timer_interval_set(Eo *obj EINA_UNUSED, Efl_Loop_Timer_Data *timer, do
timer->in = in;
if (!timer->initialized)
- _efl_loop_timer_set(timer, timer->at + in, in);
+ {
+ timer->at = ecore_time_get();
+ _efl_loop_timer_set(timer, timer->at + in, in);
+ }
}
EOLIAN static double
@@ -362,9 +369,15 @@ _efl_loop_timer_efl_object_event_freeze(Eo *obj EINA_UNUSED, Efl_Loop_Timer_Data
if (timer->frozen)
return;
- now = ecore_time_get();
+ if (EINA_UNLIKELY(!timer->initialized))
+ {
+ ERR("Attempt freezing an non initialized timer.");
+ return;
+ }
+ now = ecore_loop_time_get();
timer->pending = timer->at - now;
+
timer->at = 0.0;
timer->frozen = 1;
@@ -442,6 +455,12 @@ _efl_loop_timer_util_instanciate(Efl_Loop_Timer_Data *timer)
return ;
}
+ if (!timer->initialized)
+ {
+ ERR("Trying to instanciate an uninitialized timer is impossible.");
+ return ;
+ }
+
EINA_INLIST_REVERSE_FOREACH(timers, t2)
{
if (timer->at > t2->at)
@@ -459,6 +478,12 @@ static void
_efl_loop_timer_util_delay(Efl_Loop_Timer_Data *timer,
double add)
{
+ if (!timer->initialized)
+ {
+ ERR("Impossible to delay an uninitialized timer.");
+ return ;
+ }
+
if (timer->frozen)
{
timer->pending += add;
@@ -556,6 +581,7 @@ _efl_loop_timer_after_get(Efl_Loop_Timer_Data *base)
EINA_INLIST_FOREACH(EINA_INLIST_GET(base)->next, timer)
{
+ if (EINA_UNLIKELY(!timer->initialized)) continue; // This shouldn't happen
if (timer->at >= maxtime) break;
if (!timer->just_added)
valid_timer = timer;
@@ -580,6 +606,7 @@ _efl_loop_timer_next_get(void)
now = ecore_loop_time_get();
in = first->at - now;
if (in < 0) in = 0;
+
return in;
}