Reschedule timer_current in case of inner mainloop
authorlucas <lucas@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Fri, 28 May 2010 02:31:02 +0000 (02:31 +0000)
committerlucas <lucas@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Fri, 28 May 2010 02:31:02 +0000 (02:31 +0000)
commitc0f511c5cb8f7c85ea32676e30108c26042d5c56
treed92ecef445eced7e70963fb0ed31e5ef66f447f2
parentf5618b45d5f05922eec0371b3b3f14aac6304cf3
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, &times);
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>

git-svn-id: http://svn.enlightenment.org/svn/e/trunk/ecore@49245 7cbeb6ba-43b4-40fd-8cce-4c39aea84d33
src/lib/ecore/ecore_timer.c
src/tests/ecore_test_ecore.c