From: Hyunho Kang Date: Thu, 13 Apr 2017 12:51:13 +0000 (+0900) Subject: Fix tick per sec/min bug X-Git-Tag: accepted/tizen/3.0/common/20170510.183011^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=cf056a6e5f77c35786a393657931b453a5ccf411;p=platform%2Fcore%2Fappfw%2Fappcore-watch.git Fix tick per sec/min bug When a time tick was set with a long term like 30 seconds, the tick was not called at the correct time with a very small error, so the next time tick was set equal to the previous target tick time. This causes an unintended callback called. To solve this problem, it store the next time tick before set the timer, and when the tick callback is called, if the current time's next tick is same as the stored time, set the timer by calculating the stored time's next tick. Change-Id: Ib22470c5810818ab4871abcd3a31ce9278c5008e Signed-off-by: Hyunho Kang --- diff --git a/src/appcore-watch.c b/src/appcore-watch.c index 9b704da..ba11925 100755 --- a/src/appcore-watch.c +++ b/src/appcore-watch.c @@ -176,6 +176,7 @@ struct watch_core { }; static struct watch_core core; +static double __prev_target_tick = -1; static int __sys_lowmem_post(void *data, void *evt); static int __sys_lowmem(void *data, void *evt); @@ -898,6 +899,7 @@ static void __watch_core_time_tick_cancel(void) if (watch_tick) { ecore_timer_del(watch_tick); watch_tick = NULL; + __prev_target_tick = -1; } } @@ -907,11 +909,13 @@ static double __get_next_tick_sec() double term = 1.0; double sec = 1.0; int idx; + double target; + struct watch_time_s timeinfo; __get_timeinfo(&timeinfo); cur_time_in_milli = timeinfo.hour24 * 60 * 60 * 1000 + timeinfo.minute * 60 * 1000 + - timeinfo.minute * 60 * 1000 + timeinfo.second * 1000 + timeinfo.millisecond; + timeinfo.second * 1000 + timeinfo.millisecond; if (app_tick_type == WATCH_APP_TIME_TICKS_PER_SECOND) { term = (double)ONE_SECOND / (double)app_tick_resolution; @@ -924,7 +928,13 @@ static double __get_next_tick_sec() } idx = cur_time_in_milli / term; - sec = (((idx + 1) * term) - cur_time_in_milli) / 1000.0; + target = (idx + 1) * term; + + if (__prev_target_tick == target) + target = __prev_target_tick + term; + + sec = (target - cur_time_in_milli) / 1000.0; + __prev_target_tick = target; return sec; }