2009-01-31 10:33:39 -08:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include <config.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
2012-11-18 22:26:48 -08:00
|
|
|
#include <Eo.h>
|
|
|
|
|
2003-09-23 01:09:32 -07:00
|
|
|
#include "Ecore.h"
|
2009-12-22 13:15:12 -08:00
|
|
|
#include "ecore_private.h"
|
2003-09-23 01:09:32 -07:00
|
|
|
|
2016-05-03 14:42:20 -07:00
|
|
|
#define MY_CLASS EFL_TIMER_CLASS
|
|
|
|
#define MY_CLASS_NAME "Efl_Timer"
|
2012-10-10 01:19:58 -07:00
|
|
|
|
|
|
|
#define ECORE_TIMER_CHECK(obj) \
|
2016-05-03 14:42:20 -07:00
|
|
|
if (!eo_isa((obj), MY_CLASS)) \
|
2012-10-10 01:19:58 -07:00
|
|
|
return
|
|
|
|
|
2016-05-03 14:42:20 -07:00
|
|
|
struct _Efl_Timer_Data
|
2011-12-11 00:29:35 -08:00
|
|
|
{
|
|
|
|
EINA_INLIST;
|
2016-05-04 13:37:39 -07:00
|
|
|
|
|
|
|
Eo *object;
|
|
|
|
|
|
|
|
double in;
|
|
|
|
double at;
|
|
|
|
double pending;
|
|
|
|
|
|
|
|
int listening;
|
|
|
|
|
|
|
|
unsigned char just_added : 1;
|
|
|
|
unsigned char frozen : 1;
|
|
|
|
unsigned char initialized : 1;
|
2011-12-11 00:29:35 -08:00
|
|
|
};
|
|
|
|
|
2016-05-03 14:42:20 -07:00
|
|
|
typedef struct _Efl_Timer_Data Efl_Timer_Data;
|
2012-10-10 01:19:58 -07:00
|
|
|
|
2016-05-04 13:37:39 -07:00
|
|
|
static void _efl_timer_util_delay(Efl_Timer_Data *timer,
|
|
|
|
double add);
|
|
|
|
static void _efl_timer_util_instanciate(Efl_Timer_Data *timer);
|
|
|
|
static void _efl_timer_set(Efl_Timer_Data *timer,
|
|
|
|
double at,
|
|
|
|
double in);
|
|
|
|
|
|
|
|
static Eina_Inlist *timers = NULL;
|
|
|
|
static Eina_Inlist *suspended = NULL;
|
2010-01-03 13:55:50 -08:00
|
|
|
|
2016-05-03 14:42:20 -07:00
|
|
|
static Efl_Timer_Data *timer_current = NULL;
|
2016-05-04 13:37:39 -07:00
|
|
|
|
|
|
|
static int timers_added = 0;
|
|
|
|
|
2011-10-20 22:40:39 -07:00
|
|
|
static double last_check = 0.0;
|
|
|
|
static double precision = 10.0 / 1000000.0;
|
2010-10-17 00:03:28 -07:00
|
|
|
|
2008-11-13 12:42:01 -08:00
|
|
|
EAPI double
|
|
|
|
ecore_timer_precision_get(void)
|
|
|
|
{
|
2012-03-29 01:52:25 -07:00
|
|
|
EINA_MAIN_LOOP_CHECK_RETURN_VAL(0.0);
|
2008-11-13 12:42:01 -08:00
|
|
|
return precision;
|
|
|
|
}
|
|
|
|
|
|
|
|
EAPI void
|
|
|
|
ecore_timer_precision_set(double value)
|
|
|
|
{
|
2012-03-29 01:52:25 -07:00
|
|
|
EINA_MAIN_LOOP_CHECK_RETURN;
|
2011-07-05 04:13:29 -07:00
|
|
|
|
2008-11-13 12:42:01 -08:00
|
|
|
if (value < 0.0)
|
|
|
|
{
|
2010-09-29 23:09:20 -07:00
|
|
|
ERR("Precision %f less than zero, ignored", value);
|
2016-01-14 14:52:37 -08:00
|
|
|
return ;
|
2008-11-13 12:42:01 -08:00
|
|
|
}
|
|
|
|
precision = value;
|
|
|
|
}
|
|
|
|
|
2016-05-04 13:37:39 -07:00
|
|
|
static Eina_Bool
|
|
|
|
_check_timer_event_catcher_add(void *data, const Eo_Event *event)
|
2003-09-23 01:09:32 -07:00
|
|
|
{
|
2016-05-04 13:37:39 -07:00
|
|
|
const Eo_Callback_Array_Item *array = event->info;
|
|
|
|
Efl_Timer_Data *timer = data;
|
|
|
|
int i;
|
2003-09-23 01:09:32 -07:00
|
|
|
|
2016-05-04 13:37:39 -07:00
|
|
|
for (i = 0; array[i].desc != NULL; i++)
|
|
|
|
{
|
|
|
|
if (array[i].desc == EFL_TIMER_EVENT_TICK)
|
|
|
|
{
|
|
|
|
if (timer->listening++ > 0) return EO_CALLBACK_CONTINUE;
|
|
|
|
_efl_timer_util_instanciate(timer);
|
|
|
|
// No need to walk more than once per array as you can not del
|
|
|
|
// a partial array
|
|
|
|
return EO_CALLBACK_CONTINUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return EO_CALLBACK_CONTINUE;
|
2012-10-10 01:19:58 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static Eina_Bool
|
2016-05-04 13:37:39 -07:00
|
|
|
_check_timer_event_catcher_del(void *data, const Eo_Event *event)
|
2012-10-10 01:19:58 -07:00
|
|
|
{
|
2016-05-04 13:37:39 -07:00
|
|
|
const Eo_Callback_Array_Item *array = event->info;
|
|
|
|
Efl_Timer_Data *timer = data;
|
|
|
|
int i;
|
2012-10-10 01:19:58 -07:00
|
|
|
|
2016-05-04 13:37:39 -07:00
|
|
|
for (i = 0; array[i].desc != NULL; i++)
|
2012-10-10 01:19:58 -07:00
|
|
|
{
|
2016-05-04 13:37:39 -07:00
|
|
|
if (array[i].desc == EFL_TIMER_EVENT_TICK)
|
|
|
|
{
|
|
|
|
if ((--timer->listening) > 0) return EO_CALLBACK_CONTINUE;
|
|
|
|
_efl_timer_util_instanciate(timer);
|
|
|
|
return EO_CALLBACK_CONTINUE;
|
|
|
|
}
|
2012-10-10 01:19:58 -07:00
|
|
|
}
|
|
|
|
|
2016-05-04 13:37:39 -07:00
|
|
|
return EO_CALLBACK_CONTINUE;
|
|
|
|
}
|
2012-10-10 01:19:58 -07:00
|
|
|
|
2016-05-04 13:37:39 -07:00
|
|
|
EO_CALLBACKS_ARRAY_DEFINE(timer_watch,
|
2016-05-17 09:14:47 -07:00
|
|
|
{ EO_EVENT_CALLBACK_ADD, _check_timer_event_catcher_add },
|
|
|
|
{ EO_EVENT_CALLBACK_DEL, _check_timer_event_catcher_del });
|
2012-10-10 01:19:58 -07:00
|
|
|
|
2016-05-04 13:37:39 -07:00
|
|
|
EOLIAN static Eo *
|
|
|
|
_efl_timer_eo_base_constructor(Eo *obj, Efl_Timer_Data *timer)
|
|
|
|
{
|
|
|
|
eo_constructor(eo_super(obj, MY_CLASS));
|
|
|
|
|
|
|
|
eo_event_callback_array_add(obj, timer_watch(), timer);
|
|
|
|
|
|
|
|
eo_wref_add(obj, &timer->object);
|
|
|
|
|
|
|
|
timer->at = ecore_time_get();
|
|
|
|
timer->initialized = 0;
|
2011-05-17 10:32:32 -07:00
|
|
|
|
2016-05-04 13:37:39 -07:00
|
|
|
return obj;
|
2012-10-10 01:19:58 -07:00
|
|
|
}
|
2011-05-17 10:32:32 -07:00
|
|
|
|
2016-05-04 13:37:39 -07:00
|
|
|
|
|
|
|
EOLIAN static Eo *
|
|
|
|
_efl_timer_eo_base_finalize(Eo *obj, Efl_Timer_Data *pd)
|
2012-10-10 01:19:58 -07:00
|
|
|
{
|
2016-05-04 13:37:39 -07:00
|
|
|
_efl_timer_util_instanciate(pd);
|
2012-10-10 01:19:58 -07:00
|
|
|
|
2016-05-04 13:37:39 -07:00
|
|
|
return eo_finalize(eo_super(obj, MY_CLASS));
|
|
|
|
}
|
2012-10-10 01:19:58 -07:00
|
|
|
|
2016-05-04 13:37:39 -07:00
|
|
|
typedef struct _Ecore_Timer_Legacy Ecore_Timer_Legacy;
|
|
|
|
struct _Ecore_Timer_Legacy
|
|
|
|
{
|
|
|
|
Ecore_Task_Cb func;
|
2016-05-05 21:55:43 -07:00
|
|
|
|
2016-05-04 13:37:39 -07:00
|
|
|
const void *data;
|
2016-05-05 21:55:43 -07:00
|
|
|
|
|
|
|
Eina_Bool inside_call : 1;
|
|
|
|
Eina_Bool delete_me : 1;
|
2016-05-04 13:37:39 -07:00
|
|
|
};
|
|
|
|
|
2016-05-05 21:55:43 -07:00
|
|
|
static Eina_Bool
|
|
|
|
_ecore_timer_legacy_del(void *data, const Eo_Event *event EINA_UNUSED)
|
|
|
|
{
|
|
|
|
Ecore_Timer_Legacy *legacy = data;
|
|
|
|
|
|
|
|
free(legacy);
|
|
|
|
|
|
|
|
return EO_CALLBACK_CONTINUE;
|
|
|
|
}
|
|
|
|
|
2016-05-04 13:37:39 -07:00
|
|
|
static Eina_Bool
|
|
|
|
_ecore_timer_legacy_tick(void *data, const Eo_Event *event)
|
|
|
|
{
|
|
|
|
Ecore_Timer_Legacy *legacy = data;
|
|
|
|
|
2016-05-05 21:55:43 -07:00
|
|
|
legacy->inside_call = 1;
|
|
|
|
if (!_ecore_call_task_cb(legacy->func, (void*)legacy->data) ||
|
|
|
|
legacy->delete_me)
|
Revert "Eo: Remove eo_del() and make eo_unref() the replacement."
This reverts commit 546ff7bbba788ec834c5608361c0834853f2d5d7.
It seems that eo_del() is useful and removing it was creating bugs.
The issue is that the way we defined parents in eo, both the parent and
the programmer share a reference to the object. When we eo_unref() that
reference as the programmer, eo has no way to know it's this specific
reference we are freeing, and not a general one, so in some
circumstances, for example:
eo_ref(child);
eo_unref(child); // trying to delete here
eo_unref(container); // container is deleted here
eo_unref(child); // child already has 0 refs before this point.
We would have an issue with references and objects being freed too soon
and in general, issue with the references.
Having eo_del() solves that, because this one explicitly unparents if
there is a parent, meaning the reference ownership is explicitly taken
by the programmer.
eo_del() is essentially a convenience function around "check if has
parent, and if so unparent, otherwise, unref". Which should be used when
you want to delete an object although it has a parent, and is equivalent
to eo_unref() when it doesn't have one.
2016-06-01 05:14:30 -07:00
|
|
|
eo_del(event->object);
|
2016-05-04 13:37:39 -07:00
|
|
|
|
|
|
|
return EO_CALLBACK_CONTINUE;
|
2003-09-23 01:09:32 -07:00
|
|
|
}
|
|
|
|
|
2016-05-05 21:55:43 -07:00
|
|
|
EO_CALLBACKS_ARRAY_DEFINE(legacy_timer,
|
|
|
|
{ EFL_TIMER_EVENT_TICK, _ecore_timer_legacy_tick },
|
2016-05-17 09:14:47 -07:00
|
|
|
{ EO_EVENT_DEL, _ecore_timer_legacy_del });
|
2016-05-05 21:55:43 -07:00
|
|
|
|
2016-05-04 13:37:39 -07:00
|
|
|
EAPI Ecore_Timer *
|
|
|
|
ecore_timer_add(double in,
|
|
|
|
Ecore_Task_Cb func,
|
|
|
|
const void *data)
|
2012-10-10 01:19:58 -07:00
|
|
|
{
|
2016-05-04 13:37:39 -07:00
|
|
|
Ecore_Timer_Legacy *legacy;
|
|
|
|
Eo *timer;
|
2012-10-10 01:19:58 -07:00
|
|
|
|
2016-05-04 13:37:39 -07:00
|
|
|
legacy = calloc(1, sizeof (Ecore_Timer_Legacy));
|
|
|
|
if (!legacy) return NULL;
|
2012-10-10 01:19:58 -07:00
|
|
|
|
2016-05-04 13:37:39 -07:00
|
|
|
legacy->func = func;
|
|
|
|
legacy->data = data;
|
|
|
|
timer = eo_add(MY_CLASS, ecore_main_loop_get(),
|
2016-05-05 21:55:43 -07:00
|
|
|
eo_event_callback_array_add(eo_self, legacy_timer(), legacy),
|
2016-05-04 13:37:39 -07:00
|
|
|
eo_key_data_set(eo_self, "_legacy", legacy),
|
|
|
|
efl_timer_interval_set(eo_self, in));
|
|
|
|
|
|
|
|
return timer;
|
2012-10-10 01:19:58 -07:00
|
|
|
}
|
|
|
|
|
2009-03-22 19:13:50 -07:00
|
|
|
EAPI Ecore_Timer *
|
2011-10-20 22:40:39 -07:00
|
|
|
ecore_timer_loop_add(double in,
|
|
|
|
Ecore_Task_Cb func,
|
|
|
|
const void *data)
|
2009-03-22 19:13:50 -07:00
|
|
|
{
|
2016-05-04 13:37:39 -07:00
|
|
|
Ecore_Timer_Legacy *legacy;
|
|
|
|
Eo *timer;
|
|
|
|
|
|
|
|
legacy = calloc(1, sizeof (Ecore_Timer_Legacy));
|
|
|
|
if (!legacy) return NULL;
|
|
|
|
|
|
|
|
legacy->func = func;
|
|
|
|
legacy->data = data;
|
|
|
|
timer = eo_add(MY_CLASS, ecore_main_loop_get(),
|
2016-05-05 21:55:43 -07:00
|
|
|
eo_event_callback_array_add(eo_self, legacy_timer(), legacy),
|
2016-05-04 13:37:39 -07:00
|
|
|
eo_key_data_set(eo_self, "_legacy", legacy),
|
|
|
|
efl_timer_loop_reset(eo_self),
|
|
|
|
efl_timer_interval_set(eo_self, in));
|
|
|
|
|
|
|
|
return timer;
|
2009-03-22 19:13:50 -07:00
|
|
|
}
|
|
|
|
|
2006-01-06 09:58:12 -08:00
|
|
|
EAPI void *
|
2003-09-23 01:09:32 -07:00
|
|
|
ecore_timer_del(Ecore_Timer *timer)
|
|
|
|
{
|
2016-05-04 13:37:39 -07:00
|
|
|
Ecore_Timer_Legacy *legacy;
|
|
|
|
void *data;
|
|
|
|
|
2012-12-24 01:35:56 -08:00
|
|
|
if (!timer) return NULL;
|
2012-03-29 01:52:25 -07:00
|
|
|
EINA_MAIN_LOOP_CHECK_RETURN_VAL(NULL);
|
2011-07-05 04:13:29 -07:00
|
|
|
|
2016-05-04 13:37:39 -07:00
|
|
|
legacy = eo_key_data_get(timer, "_legacy");
|
|
|
|
data = (void*) legacy->data;
|
|
|
|
|
2016-05-05 21:55:43 -07:00
|
|
|
if (legacy->inside_call)
|
|
|
|
legacy->delete_me = EINA_TRUE;
|
|
|
|
else
|
Revert "Eo: Remove eo_del() and make eo_unref() the replacement."
This reverts commit 546ff7bbba788ec834c5608361c0834853f2d5d7.
It seems that eo_del() is useful and removing it was creating bugs.
The issue is that the way we defined parents in eo, both the parent and
the programmer share a reference to the object. When we eo_unref() that
reference as the programmer, eo has no way to know it's this specific
reference we are freeing, and not a general one, so in some
circumstances, for example:
eo_ref(child);
eo_unref(child); // trying to delete here
eo_unref(container); // container is deleted here
eo_unref(child); // child already has 0 refs before this point.
We would have an issue with references and objects being freed too soon
and in general, issue with the references.
Having eo_del() solves that, because this one explicitly unparents if
there is a parent, meaning the reference ownership is explicitly taken
by the programmer.
eo_del() is essentially a convenience function around "check if has
parent, and if so unparent, otherwise, unref". Which should be used when
you want to delete an object although it has a parent, and is equivalent
to eo_unref() when it doesn't have one.
2016-06-01 05:14:30 -07:00
|
|
|
eo_del(timer);
|
2016-05-04 13:37:39 -07:00
|
|
|
|
|
|
|
return data;
|
2003-09-23 01:09:32 -07:00
|
|
|
}
|
|
|
|
|
2014-03-23 22:47:52 -07:00
|
|
|
EOLIAN static void
|
2016-05-03 14:42:20 -07:00
|
|
|
_efl_timer_interval_set(Eo *obj EINA_UNUSED, Efl_Timer_Data *timer, double in)
|
2005-02-22 04:39:50 -08:00
|
|
|
{
|
2012-03-29 01:52:25 -07:00
|
|
|
EINA_MAIN_LOOP_CHECK_RETURN;
|
2012-09-18 04:47:22 -07:00
|
|
|
if (in < 0.0) in = 0.0;
|
2012-10-10 01:19:58 -07:00
|
|
|
|
2005-02-22 04:39:50 -08:00
|
|
|
timer->in = in;
|
2016-05-04 13:37:39 -07:00
|
|
|
|
|
|
|
if (!timer->initialized)
|
|
|
|
_efl_timer_set(timer, timer->at + in, in);
|
2005-02-22 04:39:50 -08:00
|
|
|
}
|
|
|
|
|
2014-03-23 22:47:52 -07:00
|
|
|
EOLIAN static double
|
2016-05-03 14:42:20 -07:00
|
|
|
_efl_timer_interval_get(Eo *obj EINA_UNUSED, Efl_Timer_Data *timer)
|
2009-04-26 10:16:33 -07:00
|
|
|
{
|
2014-03-23 22:47:52 -07:00
|
|
|
double ret = -1.0;
|
2009-04-26 10:16:33 -07:00
|
|
|
|
2014-04-17 12:08:43 -07:00
|
|
|
EINA_MAIN_LOOP_CHECK_RETURN_VAL(ret);
|
2014-03-23 22:47:52 -07:00
|
|
|
ret = timer->in;
|
|
|
|
|
|
|
|
return ret;
|
2009-04-26 10:16:33 -07:00
|
|
|
}
|
|
|
|
|
2014-03-23 22:47:52 -07:00
|
|
|
EOLIAN static void
|
2016-05-04 13:37:39 -07:00
|
|
|
_efl_timer_delay(Eo *obj EINA_UNUSED, Efl_Timer_Data *pd, double add)
|
2012-10-10 01:19:58 -07:00
|
|
|
{
|
2012-03-29 01:52:25 -07:00
|
|
|
EINA_MAIN_LOOP_CHECK_RETURN;
|
2008-04-11 16:39:55 -07:00
|
|
|
|
2016-05-04 13:37:39 -07:00
|
|
|
_efl_timer_util_delay(pd, add);
|
2008-04-11 16:39:55 -07:00
|
|
|
}
|
|
|
|
|
2014-03-23 22:47:52 -07:00
|
|
|
EOLIAN static void
|
2016-05-04 13:37:39 -07:00
|
|
|
_efl_timer_reset(Eo *obj EINA_UNUSED, Efl_Timer_Data *timer)
|
2011-12-04 15:12:06 -08:00
|
|
|
{
|
|
|
|
double now, add;
|
2012-03-29 01:52:25 -07:00
|
|
|
EINA_MAIN_LOOP_CHECK_RETURN;
|
2012-10-10 01:19:58 -07:00
|
|
|
|
2011-12-04 15:12:06 -08:00
|
|
|
now = ecore_time_get();
|
|
|
|
|
2016-05-04 13:37:39 -07:00
|
|
|
if (!timer->initialized)
|
|
|
|
{
|
|
|
|
timer->at = now;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (timer->frozen)
|
|
|
|
add = timer->pending;
|
|
|
|
else
|
|
|
|
add = timer->at - now;
|
|
|
|
_efl_timer_util_delay(timer, timer->in - add);
|
|
|
|
}
|
|
|
|
|
|
|
|
EOLIAN static void
|
|
|
|
_efl_timer_loop_reset(Eo *obj EINA_UNUSED, Efl_Timer_Data *timer)
|
|
|
|
{
|
|
|
|
double now, add;
|
|
|
|
EINA_MAIN_LOOP_CHECK_RETURN;
|
|
|
|
|
|
|
|
now = ecore_loop_time_get();
|
|
|
|
|
|
|
|
if (!timer->initialized)
|
|
|
|
{
|
|
|
|
timer->at = now;
|
|
|
|
return ;
|
|
|
|
}
|
|
|
|
|
2011-12-04 15:12:06 -08:00
|
|
|
if (timer->frozen)
|
|
|
|
add = timer->pending;
|
|
|
|
else
|
|
|
|
add = timer->at - now;
|
2016-05-04 13:37:39 -07:00
|
|
|
_efl_timer_util_delay(timer, timer->in - add);
|
2011-12-04 15:12:06 -08:00
|
|
|
}
|
|
|
|
|
2014-03-23 22:47:52 -07:00
|
|
|
EOLIAN static double
|
2016-05-03 14:42:20 -07:00
|
|
|
_efl_timer_pending_get(Eo *obj EINA_UNUSED, Efl_Timer_Data *timer)
|
2012-10-10 01:19:58 -07:00
|
|
|
{
|
|
|
|
double now;
|
2014-03-23 22:47:52 -07:00
|
|
|
double ret = 0.0;
|
2012-10-10 01:19:58 -07:00
|
|
|
|
2014-04-17 12:08:43 -07:00
|
|
|
EINA_MAIN_LOOP_CHECK_RETURN_VAL(ret);
|
2012-10-10 01:19:58 -07:00
|
|
|
|
2008-04-11 16:39:55 -07:00
|
|
|
now = ecore_time_get();
|
|
|
|
|
|
|
|
if (timer->frozen)
|
2014-03-23 22:47:52 -07:00
|
|
|
ret = timer->pending;
|
2011-07-28 05:01:16 -07:00
|
|
|
else
|
2014-03-23 22:47:52 -07:00
|
|
|
ret = timer->at - now;
|
|
|
|
|
|
|
|
return ret;
|
2008-04-11 16:39:55 -07:00
|
|
|
}
|
2014-03-23 22:47:52 -07:00
|
|
|
|
2008-03-09 08:56:17 -07:00
|
|
|
EAPI void
|
|
|
|
ecore_timer_freeze(Ecore_Timer *timer)
|
2012-10-10 01:19:58 -07:00
|
|
|
{
|
|
|
|
ECORE_TIMER_CHECK(timer);
|
2016-03-01 10:06:28 -08:00
|
|
|
eo_event_freeze(timer);
|
2012-10-10 01:19:58 -07:00
|
|
|
}
|
|
|
|
|
2014-03-23 22:47:52 -07:00
|
|
|
EOLIAN static void
|
2016-05-03 14:42:20 -07:00
|
|
|
_efl_timer_eo_base_event_freeze(Eo *obj EINA_UNUSED, Efl_Timer_Data *timer)
|
2008-03-09 08:56:17 -07:00
|
|
|
{
|
|
|
|
double now;
|
|
|
|
|
2012-03-29 01:52:25 -07:00
|
|
|
EINA_MAIN_LOOP_CHECK_RETURN;
|
2011-07-05 04:13:29 -07:00
|
|
|
|
2016-05-04 13:37:39 -07:00
|
|
|
eo_event_freeze(eo_super(obj, MY_CLASS));
|
|
|
|
|
2008-03-09 08:56:17 -07:00
|
|
|
/* Timer already frozen */
|
|
|
|
if (timer->frozen)
|
2016-01-14 14:52:37 -08:00
|
|
|
return;
|
2008-03-09 08:56:17 -07:00
|
|
|
|
|
|
|
now = ecore_time_get();
|
|
|
|
|
|
|
|
timer->pending = timer->at - now;
|
|
|
|
timer->at = 0.0;
|
|
|
|
timer->frozen = 1;
|
2016-05-04 13:37:39 -07:00
|
|
|
|
|
|
|
_efl_timer_util_instanciate(timer);
|
2008-03-09 08:56:17 -07:00
|
|
|
}
|
|
|
|
|
2013-11-09 23:51:42 -08:00
|
|
|
EAPI Eina_Bool
|
|
|
|
ecore_timer_freeze_get(Ecore_Timer *timer)
|
|
|
|
{
|
|
|
|
int r = 0;
|
|
|
|
|
2016-03-01 10:06:28 -08:00
|
|
|
r = eo_event_freeze_count_get(timer);
|
2013-11-09 23:51:42 -08:00
|
|
|
return !!r;
|
|
|
|
}
|
|
|
|
|
2014-03-23 22:47:52 -07:00
|
|
|
EOLIAN static int
|
2016-05-03 14:42:20 -07:00
|
|
|
_efl_timer_eo_base_event_freeze_count_get(Eo *obj EINA_UNUSED, Efl_Timer_Data *timer)
|
2013-11-09 23:51:42 -08:00
|
|
|
{
|
2014-04-17 12:08:43 -07:00
|
|
|
EINA_MAIN_LOOP_CHECK_RETURN_VAL(0);
|
2013-11-09 23:51:42 -08:00
|
|
|
|
2014-03-23 22:47:52 -07:00
|
|
|
return timer->frozen;
|
2013-11-09 23:51:42 -08:00
|
|
|
}
|
|
|
|
|
2008-03-09 08:56:17 -07:00
|
|
|
EAPI void
|
|
|
|
ecore_timer_thaw(Ecore_Timer *timer)
|
2012-10-10 01:19:58 -07:00
|
|
|
{
|
|
|
|
ECORE_TIMER_CHECK(timer);
|
2016-03-01 10:06:28 -08:00
|
|
|
eo_event_thaw(timer);
|
2012-10-10 01:19:58 -07:00
|
|
|
}
|
|
|
|
|
2014-03-23 22:47:52 -07:00
|
|
|
EOLIAN static void
|
2016-05-03 14:42:20 -07:00
|
|
|
_efl_timer_eo_base_event_thaw(Eo *obj, Efl_Timer_Data *timer)
|
2008-03-09 08:56:17 -07:00
|
|
|
{
|
|
|
|
double now;
|
|
|
|
|
2012-03-29 01:52:25 -07:00
|
|
|
EINA_MAIN_LOOP_CHECK_RETURN;
|
2011-07-05 04:13:29 -07:00
|
|
|
|
2016-05-04 13:37:39 -07:00
|
|
|
eo_event_thaw(eo_super(obj, MY_CLASS));
|
|
|
|
|
2008-03-09 08:56:17 -07:00
|
|
|
/* Timer not frozen */
|
|
|
|
if (!timer->frozen)
|
2016-01-14 14:52:37 -08:00
|
|
|
return ;
|
2008-03-09 08:56:17 -07:00
|
|
|
|
2016-05-04 13:37:39 -07:00
|
|
|
suspended = eina_inlist_remove(suspended, EINA_INLIST_GET(timer));
|
2008-03-09 08:56:17 -07:00
|
|
|
now = ecore_time_get();
|
|
|
|
|
2016-05-04 13:37:39 -07:00
|
|
|
_efl_timer_set(timer, timer->pending + now, timer->in);
|
2008-03-09 08:56:17 -07:00
|
|
|
}
|
|
|
|
|
2011-05-17 10:32:32 -07:00
|
|
|
EAPI char *
|
|
|
|
ecore_timer_dump(void)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2016-05-04 13:37:39 -07:00
|
|
|
static void
|
|
|
|
_efl_timer_util_instanciate(Efl_Timer_Data *timer)
|
2011-07-28 05:01:16 -07:00
|
|
|
{
|
2016-05-04 13:37:39 -07:00
|
|
|
Efl_Timer_Data *t2;
|
|
|
|
Eina_Inlist *first;
|
2011-07-28 05:01:16 -07:00
|
|
|
|
2016-05-04 13:37:39 -07:00
|
|
|
// Remove the timer from all possible pending list
|
|
|
|
first = eina_inlist_first(EINA_INLIST_GET(timer));
|
|
|
|
if (first == timers)
|
|
|
|
timers = eina_inlist_remove(timers, EINA_INLIST_GET(timer));
|
|
|
|
else if (first == suspended)
|
|
|
|
suspended = eina_inlist_remove(suspended, EINA_INLIST_GET(timer));
|
2012-10-10 01:19:58 -07:00
|
|
|
|
2016-05-04 13:37:39 -07:00
|
|
|
// And start putting it back where it belong
|
|
|
|
if (!timer->listening || timer->frozen || timer->at <= 0.0 || timer->in < 0.0)
|
2011-07-28 05:01:16 -07:00
|
|
|
{
|
2016-05-04 13:37:39 -07:00
|
|
|
suspended = eina_inlist_prepend(suspended, EINA_INLIST_GET(timer));
|
|
|
|
return ;
|
2011-07-28 05:01:16 -07:00
|
|
|
}
|
2016-05-04 13:37:39 -07:00
|
|
|
|
|
|
|
EINA_INLIST_REVERSE_FOREACH(timers, t2)
|
2011-07-28 05:01:16 -07:00
|
|
|
{
|
2016-05-04 13:37:39 -07:00
|
|
|
if (timer->at > t2->at)
|
|
|
|
{
|
|
|
|
timers = eina_inlist_append_relative(timers,
|
|
|
|
EINA_INLIST_GET(timer),
|
|
|
|
EINA_INLIST_GET(t2));
|
|
|
|
return;
|
|
|
|
}
|
2011-07-28 05:01:16 -07:00
|
|
|
}
|
2016-05-04 13:37:39 -07:00
|
|
|
timers = eina_inlist_prepend(timers, EINA_INLIST_GET(timer));
|
2011-07-28 05:01:16 -07:00
|
|
|
}
|
|
|
|
|
2016-05-04 13:37:39 -07:00
|
|
|
static void
|
|
|
|
_efl_timer_util_delay(Efl_Timer_Data *timer,
|
|
|
|
double add)
|
2011-07-28 05:01:16 -07:00
|
|
|
{
|
2016-05-04 13:37:39 -07:00
|
|
|
if (timer->frozen)
|
2011-07-28 05:01:16 -07:00
|
|
|
{
|
2016-05-04 13:37:39 -07:00
|
|
|
timer->pending += add;
|
|
|
|
return ;
|
2011-07-28 05:01:16 -07:00
|
|
|
}
|
|
|
|
|
2016-05-04 13:37:39 -07:00
|
|
|
_efl_timer_set(timer, timer->at + add, timer->in);
|
2011-07-28 05:01:16 -07:00
|
|
|
}
|
|
|
|
|
2014-03-23 22:47:52 -07:00
|
|
|
EOLIAN static void
|
2016-05-03 14:42:20 -07:00
|
|
|
_efl_timer_eo_base_destructor(Eo *obj, Efl_Timer_Data *pd)
|
2012-10-10 01:19:58 -07:00
|
|
|
{
|
2016-05-04 13:37:39 -07:00
|
|
|
Eina_Inlist *first;
|
2012-10-10 01:19:58 -07:00
|
|
|
|
2016-05-04 13:37:39 -07:00
|
|
|
// Check if we are the current timer, if so move along
|
|
|
|
if (timer_current == pd)
|
|
|
|
timer_current = (Efl_Timer_Data *)EINA_INLIST_GET(pd)->next;
|
2012-10-10 01:19:58 -07:00
|
|
|
|
2016-05-04 13:37:39 -07:00
|
|
|
// Remove the timer from all possible pending list
|
|
|
|
first = eina_inlist_first(EINA_INLIST_GET(pd));
|
|
|
|
if (first == timers)
|
|
|
|
timers = eina_inlist_remove(timers, EINA_INLIST_GET(pd));
|
|
|
|
else if (first == suspended)
|
|
|
|
suspended = eina_inlist_remove(suspended, EINA_INLIST_GET(pd));
|
2015-05-20 06:56:45 -07:00
|
|
|
|
2016-05-04 13:37:39 -07:00
|
|
|
eo_destructor(eo_super(obj, MY_CLASS));
|
2015-05-20 06:56:45 -07:00
|
|
|
}
|
|
|
|
|
2003-09-23 01:09:32 -07:00
|
|
|
void
|
2016-05-03 14:42:20 -07:00
|
|
|
_efl_timer_shutdown(void)
|
2003-09-23 01:09:32 -07:00
|
|
|
{
|
2016-05-03 14:42:20 -07:00
|
|
|
Efl_Timer_Data *timer;
|
2008-11-29 03:23:17 -08:00
|
|
|
|
2016-05-04 13:37:39 -07:00
|
|
|
EINA_INLIST_FREE(timers, timer)
|
Revert "Eo: Remove eo_del() and make eo_unref() the replacement."
This reverts commit 546ff7bbba788ec834c5608361c0834853f2d5d7.
It seems that eo_del() is useful and removing it was creating bugs.
The issue is that the way we defined parents in eo, both the parent and
the programmer share a reference to the object. When we eo_unref() that
reference as the programmer, eo has no way to know it's this specific
reference we are freeing, and not a general one, so in some
circumstances, for example:
eo_ref(child);
eo_unref(child); // trying to delete here
eo_unref(container); // container is deleted here
eo_unref(child); // child already has 0 refs before this point.
We would have an issue with references and objects being freed too soon
and in general, issue with the references.
Having eo_del() solves that, because this one explicitly unparents if
there is a parent, meaning the reference ownership is explicitly taken
by the programmer.
eo_del() is essentially a convenience function around "check if has
parent, and if so unparent, otherwise, unref". Which should be used when
you want to delete an object although it has a parent, and is equivalent
to eo_unref() when it doesn't have one.
2016-06-01 05:14:30 -07:00
|
|
|
eo_del(timer->object);
|
2008-03-09 08:56:17 -07:00
|
|
|
|
2016-05-04 13:37:39 -07:00
|
|
|
EINA_INLIST_FREE(suspended, timer)
|
Revert "Eo: Remove eo_del() and make eo_unref() the replacement."
This reverts commit 546ff7bbba788ec834c5608361c0834853f2d5d7.
It seems that eo_del() is useful and removing it was creating bugs.
The issue is that the way we defined parents in eo, both the parent and
the programmer share a reference to the object. When we eo_unref() that
reference as the programmer, eo has no way to know it's this specific
reference we are freeing, and not a general one, so in some
circumstances, for example:
eo_ref(child);
eo_unref(child); // trying to delete here
eo_unref(container); // container is deleted here
eo_unref(child); // child already has 0 refs before this point.
We would have an issue with references and objects being freed too soon
and in general, issue with the references.
Having eo_del() solves that, because this one explicitly unparents if
there is a parent, meaning the reference ownership is explicitly taken
by the programmer.
eo_del() is essentially a convenience function around "check if has
parent, and if so unparent, otherwise, unref". Which should be used when
you want to delete an object although it has a parent, and is equivalent
to eo_unref() when it doesn't have one.
2016-06-01 05:14:30 -07:00
|
|
|
eo_del(timer->object);
|
2010-02-23 16:27:04 -08:00
|
|
|
|
|
|
|
timer_current = NULL;
|
2003-09-23 01:09:32 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-05-03 14:42:20 -07:00
|
|
|
_efl_timer_enable_new(void)
|
2003-09-23 01:09:32 -07:00
|
|
|
{
|
2016-05-03 14:42:20 -07:00
|
|
|
Efl_Timer_Data *timer;
|
2003-09-23 01:09:32 -07:00
|
|
|
|
|
|
|
if (!timers_added) return;
|
|
|
|
timers_added = 0;
|
2010-02-16 08:52:02 -08:00
|
|
|
EINA_INLIST_FOREACH(timers, timer) timer->just_added = 0;
|
2003-09-23 01:09:32 -07:00
|
|
|
}
|
|
|
|
|
Fix the bug of the first timer being added from idler.
We should start doing unit-test for ecore, accumulating these
problems. Follows the test case:
#include <Ecore.h>
#include <Eina.h>
static int _log_dom;
#define INF(...) EINA_LOG_DOM_INFO(_log_dom, __VA_ARGS__)
static int quiter(void *data)
{
INF("quit!");
ecore_main_loop_quit();
return 1;
}
static int idler(void *data)
{
INF("idler");
return 1;
}
static int cb1(void *data)
{
INF("cb1");
ecore_timer_add(0.0, quiter, NULL);
return 0;
}
int main(void)
{
ecore_init();
_log_dom = eina_log_domain_register("test", EINA_COLOR_CYAN);
/*
* Create a main loop with just idlers, there is a special case
* for just idlers without timers in ecore.
*
* From idler, add a timer that quits the application. It should
* always quit.
*
* If it does not quit, then there is a bug of new timers not
* being immediately detected and system never exits idle.
*/
INF("main: begin");
ecore_idler_add(cb1, NULL);
ecore_idler_add(idler, NULL);
ecore_main_loop_begin();
INF("main: end");
return 0;
}
SVN revision: 46405
2010-02-23 13:04:38 -08:00
|
|
|
int
|
2016-05-03 14:42:20 -07:00
|
|
|
_efl_timers_exists(void)
|
Fix the bug of the first timer being added from idler.
We should start doing unit-test for ecore, accumulating these
problems. Follows the test case:
#include <Ecore.h>
#include <Eina.h>
static int _log_dom;
#define INF(...) EINA_LOG_DOM_INFO(_log_dom, __VA_ARGS__)
static int quiter(void *data)
{
INF("quit!");
ecore_main_loop_quit();
return 1;
}
static int idler(void *data)
{
INF("idler");
return 1;
}
static int cb1(void *data)
{
INF("cb1");
ecore_timer_add(0.0, quiter, NULL);
return 0;
}
int main(void)
{
ecore_init();
_log_dom = eina_log_domain_register("test", EINA_COLOR_CYAN);
/*
* Create a main loop with just idlers, there is a special case
* for just idlers without timers in ecore.
*
* From idler, add a timer that quits the application. It should
* always quit.
*
* If it does not quit, then there is a bug of new timers not
* being immediately detected and system never exits idle.
*/
INF("main: begin");
ecore_idler_add(cb1, NULL);
ecore_idler_add(idler, NULL);
ecore_main_loop_begin();
INF("main: end");
return 0;
}
SVN revision: 46405
2010-02-23 13:04:38 -08:00
|
|
|
{
|
2016-05-04 13:37:39 -07:00
|
|
|
return !!timers;
|
Fix the bug of the first timer being added from idler.
We should start doing unit-test for ecore, accumulating these
problems. Follows the test case:
#include <Ecore.h>
#include <Eina.h>
static int _log_dom;
#define INF(...) EINA_LOG_DOM_INFO(_log_dom, __VA_ARGS__)
static int quiter(void *data)
{
INF("quit!");
ecore_main_loop_quit();
return 1;
}
static int idler(void *data)
{
INF("idler");
return 1;
}
static int cb1(void *data)
{
INF("cb1");
ecore_timer_add(0.0, quiter, NULL);
return 0;
}
int main(void)
{
ecore_init();
_log_dom = eina_log_domain_register("test", EINA_COLOR_CYAN);
/*
* Create a main loop with just idlers, there is a special case
* for just idlers without timers in ecore.
*
* From idler, add a timer that quits the application. It should
* always quit.
*
* If it does not quit, then there is a bug of new timers not
* being immediately detected and system never exits idle.
*/
INF("main: begin");
ecore_idler_add(cb1, NULL);
ecore_idler_add(idler, NULL);
ecore_main_loop_begin();
INF("main: end");
return 0;
}
SVN revision: 46405
2010-02-23 13:04:38 -08:00
|
|
|
}
|
|
|
|
|
2008-11-13 12:42:01 -08:00
|
|
|
static inline Ecore_Timer *
|
2016-05-03 14:42:20 -07:00
|
|
|
_efl_timer_first_get(void)
|
2008-11-13 12:42:01 -08:00
|
|
|
{
|
2016-05-04 13:37:39 -07:00
|
|
|
Efl_Timer_Data *timer;
|
2008-11-13 12:42:01 -08:00
|
|
|
|
2016-05-04 13:37:39 -07:00
|
|
|
EINA_INLIST_FOREACH(timers, timer)
|
|
|
|
if (!timer->just_added) return timer->object;
|
2008-11-13 12:42:01 -08:00
|
|
|
|
2016-05-04 13:37:39 -07:00
|
|
|
return NULL;
|
2008-11-13 12:42:01 -08:00
|
|
|
}
|
|
|
|
|
2016-05-04 13:37:39 -07:00
|
|
|
static inline Efl_Timer_Data *
|
|
|
|
_efl_timer_after_get(Efl_Timer_Data *base)
|
2008-11-13 12:42:01 -08:00
|
|
|
{
|
2016-05-04 13:37:39 -07:00
|
|
|
Efl_Timer_Data *timer;
|
|
|
|
Efl_Timer_Data *valid_timer = base;
|
2008-11-13 12:42:01 -08:00
|
|
|
double maxtime = base->at + precision;
|
|
|
|
|
2016-05-04 13:37:39 -07:00
|
|
|
EINA_INLIST_FOREACH(EINA_INLIST_GET(base)->next, timer)
|
2011-07-26 00:01:55 -07:00
|
|
|
{
|
2016-05-04 13:37:39 -07:00
|
|
|
if (timer->at >= maxtime) break;
|
|
|
|
if (!timer->just_added)
|
2011-10-20 22:40:39 -07:00
|
|
|
valid_timer = timer;
|
2011-07-26 00:01:55 -07:00
|
|
|
}
|
2008-11-13 12:42:01 -08:00
|
|
|
|
2016-05-04 13:37:39 -07:00
|
|
|
return valid_timer;
|
2008-11-13 12:42:01 -08:00
|
|
|
}
|
|
|
|
|
2003-09-23 01:09:32 -07:00
|
|
|
double
|
2016-05-03 14:42:20 -07:00
|
|
|
_efl_timer_next_get(void)
|
2003-09-23 01:09:32 -07:00
|
|
|
{
|
2016-05-04 13:37:39 -07:00
|
|
|
Ecore_Timer *object;
|
|
|
|
Efl_Timer_Data *first;
|
2003-09-23 01:09:32 -07:00
|
|
|
double now;
|
|
|
|
double in;
|
2012-10-10 01:19:58 -07:00
|
|
|
|
2016-05-04 13:37:39 -07:00
|
|
|
object = _efl_timer_first_get();
|
|
|
|
if (!object) return -1;
|
2008-11-13 12:42:01 -08:00
|
|
|
|
2016-05-04 13:37:39 -07:00
|
|
|
first = _efl_timer_after_get(eo_data_scope_get(object, MY_CLASS));
|
2008-11-13 12:42:01 -08:00
|
|
|
|
2008-11-01 19:19:18 -07:00
|
|
|
now = ecore_loop_time_get();
|
2008-11-13 12:42:01 -08:00
|
|
|
in = first->at - now;
|
2003-09-23 01:09:32 -07:00
|
|
|
if (in < 0) in = 0;
|
|
|
|
return in;
|
2008-11-13 12:42:01 -08:00
|
|
|
}
|
2003-09-23 01:09:32 -07:00
|
|
|
|
Reschedule timer_current in case of inner mainloop
Timers' list is and *ordered list*. Therefore, timers can be added
before timer_current in an inner mainloop. Reschedule timer_current in
this case before looping through timers' list.
Thanks to Barbieri for the insight.
The following test didn't work before and it's ok now (I'm adding it to
ecore_suite too).
static int _timer3(void *data)
{
printf("timer 3, do nothing\n");
return 0;
}
static int _timer2(void *data)
{
printf("timer 2, quit inner\n");
ecore_main_loop_quit();
return 0;
}
static int _timer1(void *data)
{
int *times = data;
(*times)++;
printf("BEGIN: inner\n");
ecore_timer_add(0.3, _timer2, NULL);
ecore_timer_add(0.1, _timer3, NULL);
ecore_main_loop_begin();
printf("END: inner\n");
ecore_main_loop_quit();
return 0;
}
int main(void)
{
int times = 0;
ecore_init();
ecore_timer_add(1.0, _timer1, ×);
printf("BEGIN: main\n");
ecore_main_loop_begin();
assert(times == 1);
printf("timer1 called %d times \n", times);
printf("END: main\n");
return 0;
}
By: Lucas De Marchi <lucas.demarchi@profusion.mobi>
SVN revision: 49245
2010-05-27 19:31:02 -07:00
|
|
|
static inline void
|
2016-05-04 13:37:39 -07:00
|
|
|
_efl_timer_reschedule(Efl_Timer_Data *timer,
|
|
|
|
double when)
|
Reschedule timer_current in case of inner mainloop
Timers' list is and *ordered list*. Therefore, timers can be added
before timer_current in an inner mainloop. Reschedule timer_current in
this case before looping through timers' list.
Thanks to Barbieri for the insight.
The following test didn't work before and it's ok now (I'm adding it to
ecore_suite too).
static int _timer3(void *data)
{
printf("timer 3, do nothing\n");
return 0;
}
static int _timer2(void *data)
{
printf("timer 2, quit inner\n");
ecore_main_loop_quit();
return 0;
}
static int _timer1(void *data)
{
int *times = data;
(*times)++;
printf("BEGIN: inner\n");
ecore_timer_add(0.3, _timer2, NULL);
ecore_timer_add(0.1, _timer3, NULL);
ecore_main_loop_begin();
printf("END: inner\n");
ecore_main_loop_quit();
return 0;
}
int main(void)
{
int times = 0;
ecore_init();
ecore_timer_add(1.0, _timer1, ×);
printf("BEGIN: main\n");
ecore_main_loop_begin();
assert(times == 1);
printf("timer1 called %d times \n", times);
printf("END: main\n");
return 0;
}
By: Lucas De Marchi <lucas.demarchi@profusion.mobi>
SVN revision: 49245
2010-05-27 19:31:02 -07:00
|
|
|
{
|
2016-05-04 13:37:39 -07:00
|
|
|
if (timer->frozen) return;
|
Reschedule timer_current in case of inner mainloop
Timers' list is and *ordered list*. Therefore, timers can be added
before timer_current in an inner mainloop. Reschedule timer_current in
this case before looping through timers' list.
Thanks to Barbieri for the insight.
The following test didn't work before and it's ok now (I'm adding it to
ecore_suite too).
static int _timer3(void *data)
{
printf("timer 3, do nothing\n");
return 0;
}
static int _timer2(void *data)
{
printf("timer 2, quit inner\n");
ecore_main_loop_quit();
return 0;
}
static int _timer1(void *data)
{
int *times = data;
(*times)++;
printf("BEGIN: inner\n");
ecore_timer_add(0.3, _timer2, NULL);
ecore_timer_add(0.1, _timer3, NULL);
ecore_main_loop_begin();
printf("END: inner\n");
ecore_main_loop_quit();
return 0;
}
int main(void)
{
int times = 0;
ecore_init();
ecore_timer_add(1.0, _timer1, ×);
printf("BEGIN: main\n");
ecore_main_loop_begin();
assert(times == 1);
printf("timer1 called %d times \n", times);
printf("END: main\n");
return 0;
}
By: Lucas De Marchi <lucas.demarchi@profusion.mobi>
SVN revision: 49245
2010-05-27 19:31:02 -07:00
|
|
|
|
2016-05-04 13:37:39 -07:00
|
|
|
timers = eina_inlist_remove(timers, EINA_INLIST_GET(timer));
|
Reschedule timer_current in case of inner mainloop
Timers' list is and *ordered list*. Therefore, timers can be added
before timer_current in an inner mainloop. Reschedule timer_current in
this case before looping through timers' list.
Thanks to Barbieri for the insight.
The following test didn't work before and it's ok now (I'm adding it to
ecore_suite too).
static int _timer3(void *data)
{
printf("timer 3, do nothing\n");
return 0;
}
static int _timer2(void *data)
{
printf("timer 2, quit inner\n");
ecore_main_loop_quit();
return 0;
}
static int _timer1(void *data)
{
int *times = data;
(*times)++;
printf("BEGIN: inner\n");
ecore_timer_add(0.3, _timer2, NULL);
ecore_timer_add(0.1, _timer3, NULL);
ecore_main_loop_begin();
printf("END: inner\n");
ecore_main_loop_quit();
return 0;
}
int main(void)
{
int times = 0;
ecore_init();
ecore_timer_add(1.0, _timer1, ×);
printf("BEGIN: main\n");
ecore_main_loop_begin();
assert(times == 1);
printf("timer1 called %d times \n", times);
printf("END: main\n");
return 0;
}
By: Lucas De Marchi <lucas.demarchi@profusion.mobi>
SVN revision: 49245
2010-05-27 19:31:02 -07:00
|
|
|
|
|
|
|
/* if the timer would have gone off more than 15 seconds ago,
|
|
|
|
* assume that the system hung and set the timer to go off
|
|
|
|
* timer->in from now. this handles system hangs, suspends
|
|
|
|
* and more, so ecore will only "replay" the timers while
|
|
|
|
* the system is suspended if it is suspended for less than
|
|
|
|
* 15 seconds (basically). this also handles if the process
|
|
|
|
* is stopped in a debugger or IO and other handling gets
|
|
|
|
* really slow within the main loop.
|
|
|
|
*/
|
|
|
|
if ((timer->at + timer->in) < (when - 15.0))
|
2016-05-04 13:37:39 -07:00
|
|
|
_efl_timer_set(timer, when + timer->in, timer->in);
|
Reschedule timer_current in case of inner mainloop
Timers' list is and *ordered list*. Therefore, timers can be added
before timer_current in an inner mainloop. Reschedule timer_current in
this case before looping through timers' list.
Thanks to Barbieri for the insight.
The following test didn't work before and it's ok now (I'm adding it to
ecore_suite too).
static int _timer3(void *data)
{
printf("timer 3, do nothing\n");
return 0;
}
static int _timer2(void *data)
{
printf("timer 2, quit inner\n");
ecore_main_loop_quit();
return 0;
}
static int _timer1(void *data)
{
int *times = data;
(*times)++;
printf("BEGIN: inner\n");
ecore_timer_add(0.3, _timer2, NULL);
ecore_timer_add(0.1, _timer3, NULL);
ecore_main_loop_begin();
printf("END: inner\n");
ecore_main_loop_quit();
return 0;
}
int main(void)
{
int times = 0;
ecore_init();
ecore_timer_add(1.0, _timer1, ×);
printf("BEGIN: main\n");
ecore_main_loop_begin();
assert(times == 1);
printf("timer1 called %d times \n", times);
printf("END: main\n");
return 0;
}
By: Lucas De Marchi <lucas.demarchi@profusion.mobi>
SVN revision: 49245
2010-05-27 19:31:02 -07:00
|
|
|
else
|
2016-05-04 13:37:39 -07:00
|
|
|
_efl_timer_set(timer, timer->at + timer->in, timer->in);
|
Reschedule timer_current in case of inner mainloop
Timers' list is and *ordered list*. Therefore, timers can be added
before timer_current in an inner mainloop. Reschedule timer_current in
this case before looping through timers' list.
Thanks to Barbieri for the insight.
The following test didn't work before and it's ok now (I'm adding it to
ecore_suite too).
static int _timer3(void *data)
{
printf("timer 3, do nothing\n");
return 0;
}
static int _timer2(void *data)
{
printf("timer 2, quit inner\n");
ecore_main_loop_quit();
return 0;
}
static int _timer1(void *data)
{
int *times = data;
(*times)++;
printf("BEGIN: inner\n");
ecore_timer_add(0.3, _timer2, NULL);
ecore_timer_add(0.1, _timer3, NULL);
ecore_main_loop_begin();
printf("END: inner\n");
ecore_main_loop_quit();
return 0;
}
int main(void)
{
int times = 0;
ecore_init();
ecore_timer_add(1.0, _timer1, ×);
printf("BEGIN: main\n");
ecore_main_loop_begin();
assert(times == 1);
printf("timer1 called %d times \n", times);
printf("END: main\n");
return 0;
}
By: Lucas De Marchi <lucas.demarchi@profusion.mobi>
SVN revision: 49245
2010-05-27 19:31:02 -07:00
|
|
|
}
|
|
|
|
|
2011-09-01 20:29:11 -07:00
|
|
|
void
|
2016-05-03 14:42:20 -07:00
|
|
|
_efl_timer_expired_timers_call(double when)
|
2011-09-01 20:29:11 -07:00
|
|
|
{
|
|
|
|
/* call the first expired timer until no expired timers exist */
|
2016-05-03 14:42:20 -07:00
|
|
|
while (_efl_timer_expired_call(when)) ;
|
2011-09-01 20:29:11 -07:00
|
|
|
}
|
|
|
|
|
2003-09-23 01:09:32 -07:00
|
|
|
int
|
2016-05-03 14:42:20 -07:00
|
|
|
_efl_timer_expired_call(double when)
|
2003-09-23 01:09:32 -07:00
|
|
|
{
|
|
|
|
if (!timers) return 0;
|
2005-04-04 09:01:39 -07:00
|
|
|
if (last_check > when)
|
|
|
|
{
|
2016-05-03 14:42:20 -07:00
|
|
|
Efl_Timer_Data *timer;
|
2010-09-29 23:09:20 -07:00
|
|
|
/* User set time backwards */
|
|
|
|
EINA_INLIST_FOREACH(timers, timer) timer->at -= (last_check - when);
|
2005-04-04 09:01:39 -07:00
|
|
|
}
|
|
|
|
last_check = when;
|
2010-02-23 16:27:04 -08:00
|
|
|
|
|
|
|
if (!timer_current)
|
2003-09-23 01:09:32 -07:00
|
|
|
{
|
2010-09-29 23:09:20 -07:00
|
|
|
/* regular main loop, start from head */
|
2016-05-04 13:37:39 -07:00
|
|
|
timer_current = (Efl_Timer_Data *)timers;
|
2010-02-23 16:27:04 -08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-09-29 23:09:20 -07:00
|
|
|
/* recursive main loop, continue from where we were */
|
2016-05-03 14:42:20 -07:00
|
|
|
Efl_Timer_Data *timer_old = timer_current;
|
2016-05-04 13:37:39 -07:00
|
|
|
|
2016-05-03 14:42:20 -07:00
|
|
|
timer_current = (Efl_Timer_Data *)EINA_INLIST_GET(timer_current)->next;
|
2016-05-04 13:37:39 -07:00
|
|
|
_efl_timer_reschedule(timer_old, when);
|
2010-02-23 16:27:04 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
while (timer_current)
|
|
|
|
{
|
2016-05-03 14:42:20 -07:00
|
|
|
Efl_Timer_Data *timer = timer_current;
|
2010-09-29 23:09:20 -07:00
|
|
|
|
|
|
|
if (timer->at > when)
|
|
|
|
{
|
|
|
|
timer_current = NULL; /* ended walk, next should restart. */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-05-04 13:37:39 -07:00
|
|
|
if (timer->just_added)
|
2010-09-29 23:09:20 -07:00
|
|
|
{
|
2016-05-03 14:42:20 -07:00
|
|
|
timer_current = (Efl_Timer_Data *)EINA_INLIST_GET(timer_current)->next;
|
2010-09-29 23:09:20 -07:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2016-05-04 13:37:39 -07:00
|
|
|
eo_ref(timer->object);
|
2015-05-10 03:05:54 -07:00
|
|
|
eina_evlog("+timer", timer, 0.0, NULL);
|
2016-05-04 13:37:39 -07:00
|
|
|
eo_event_callback_call(timer->object, EFL_TIMER_EVENT_TICK, NULL);
|
2015-05-10 03:05:54 -07:00
|
|
|
eina_evlog("-timer", timer, 0.0, NULL);
|
2010-09-29 23:09:20 -07:00
|
|
|
|
2016-05-04 13:37:39 -07:00
|
|
|
/* may have changed in recursive main loops */
|
|
|
|
/* this current timer can not die yet as we hold a reference on it */
|
|
|
|
if (timer_current)
|
2016-05-03 14:42:20 -07:00
|
|
|
timer_current = (Efl_Timer_Data *)EINA_INLIST_GET(timer_current)->next;
|
2010-09-29 23:09:20 -07:00
|
|
|
|
2016-05-04 13:37:39 -07:00
|
|
|
_efl_timer_reschedule(timer, when);
|
|
|
|
eo_unref(timer->object);
|
2003-09-23 01:09:32 -07:00
|
|
|
}
|
|
|
|
return 0;
|
2008-11-29 03:23:17 -08:00
|
|
|
}
|
2003-09-23 01:09:32 -07:00
|
|
|
|
|
|
|
static void
|
2016-05-04 13:37:39 -07:00
|
|
|
_efl_timer_set(Efl_Timer_Data *timer,
|
|
|
|
double at,
|
|
|
|
double in)
|
2003-09-23 01:09:32 -07:00
|
|
|
{
|
|
|
|
timers_added = 1;
|
|
|
|
timer->at = at;
|
|
|
|
timer->in = in;
|
|
|
|
timer->just_added = 1;
|
2016-05-04 13:37:39 -07:00
|
|
|
timer->initialized = 1;
|
2008-03-09 08:56:17 -07:00
|
|
|
timer->frozen = 0;
|
|
|
|
timer->pending = 0.0;
|
2016-05-04 13:37:39 -07:00
|
|
|
|
|
|
|
_efl_timer_util_instanciate(timer);
|
2003-09-23 01:09:32 -07:00
|
|
|
}
|
2011-05-17 10:32:32 -07:00
|
|
|
|
2016-05-03 14:42:20 -07:00
|
|
|
#include "efl_timer.eo.c"
|