1
0
mirror of https://github.com/lvgl/lvgl.git synced 2025-01-28 07:03:00 +08:00

fix(timer): remove the code duplication in lv_timer_exec (#2708)

and fix some minor comment issue

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
This commit is contained in:
Xiang Xiao 2021-10-21 03:50:30 -05:00 committed by GitHub
parent 0d48396f25
commit 7339cff139
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 21 deletions

View File

@ -60,7 +60,7 @@ void _lv_timer_core_init(void)
} }
/** /**
* Call it periodically to handle lv_timers. * Call it periodically to handle lv_timers.
* @return the time after which it must be called again * @return the time after which it must be called again
*/ */
LV_ATTRIBUTE_TIMER_HANDLER uint32_t lv_timer_handler(void) LV_ATTRIBUTE_TIMER_HANDLER uint32_t lv_timer_handler(void)
@ -69,12 +69,14 @@ LV_ATTRIBUTE_TIMER_HANDLER uint32_t lv_timer_handler(void)
/*Avoid concurrent running of the timer handler*/ /*Avoid concurrent running of the timer handler*/
static bool already_running = false; static bool already_running = false;
if(already_running) return 1; if(already_running) {
TIMER_TRACE("already running, concurrent calls are not allow, returning");
return 1;
}
already_running = true; already_running = true;
if(lv_timer_run == false) { if(lv_timer_run == false) {
already_running = false; /*Release mutex*/ already_running = false; /*Release mutex*/
TIMER_TRACE("already running, concurrent calls are not allow, returning");
return 1; return 1;
} }
@ -85,7 +87,7 @@ LV_ATTRIBUTE_TIMER_HANDLER uint32_t lv_timer_handler(void)
if(handler_start == 0) { if(handler_start == 0) {
static uint32_t run_cnt = 0; static uint32_t run_cnt = 0;
run_cnt ++; run_cnt++;
if(run_cnt > 100) { if(run_cnt > 100) {
run_cnt = 0; run_cnt = 0;
LV_LOG_WARN("It seems lv_tick_inc() is not called."); LV_LOG_WARN("It seems lv_tick_inc() is not called.");
@ -141,6 +143,7 @@ LV_ATTRIBUTE_TIMER_HANDLER uint32_t lv_timer_handler(void)
TIMER_TRACE("finished (%d ms until the next timer call)", time_till_next); TIMER_TRACE("finished (%d ms until the next timer call)", time_till_next);
return time_till_next; return time_till_next;
} }
/** /**
* Create an "empty" timer. It needs to initialized with at least * Create an "empty" timer. It needs to initialized with at least
* `lv_timer_set_cb` and `lv_timer_set_period` * `lv_timer_set_cb` and `lv_timer_set_period`
@ -168,7 +171,7 @@ lv_timer_t * lv_timer_create(lv_timer_cb_t timer_xcb, uint32_t period, void * us
LV_ASSERT_MALLOC(new_timer); LV_ASSERT_MALLOC(new_timer);
if(new_timer == NULL) return NULL; if(new_timer == NULL) return NULL;
new_timer->period = period; new_timer->period = period;
new_timer->timer_cb = timer_xcb; new_timer->timer_cb = timer_xcb;
new_timer->repeat_count = -1; new_timer->repeat_count = -1;
new_timer->paused = 0; new_timer->paused = 0;
@ -297,12 +300,6 @@ static bool lv_timer_exec(lv_timer_t * timer)
{ {
if(timer->paused) return false; if(timer->paused) return false;
if(timer->repeat_count == 0) {
TIMER_TRACE("deleting timer with %p callback because the repeat count is over", timer->timer_cb);
lv_timer_del(timer);
return false;
}
bool exec = false; bool exec = false;
if(lv_timer_time_remaining(timer) == 0) { if(lv_timer_time_remaining(timer) == 0) {
/* Decrement the repeat count before executing the timer_cb. /* Decrement the repeat count before executing the timer_cb.
@ -315,17 +312,16 @@ static bool lv_timer_exec(lv_timer_t * timer)
if(timer->timer_cb && original_repeat_count != 0) timer->timer_cb(timer); if(timer->timer_cb && original_repeat_count != 0) timer->timer_cb(timer);
TIMER_TRACE("timer callback %p finished", timer->timer_cb); TIMER_TRACE("timer callback %p finished", timer->timer_cb);
LV_ASSERT_MEM_INTEGRITY(); LV_ASSERT_MEM_INTEGRITY();
/*Delete if it was a one shot lv_timer*/
if(timer_deleted == false) { /*The timer might be deleted by itself as well*/
if(timer->repeat_count == 0) {
TIMER_TRACE("deleting timer with %p callback because the repeat count is over", timer->timer_cb);
lv_timer_del(timer);
}
}
exec = true; exec = true;
} }
if(timer_deleted == false) { /*The timer might be deleted by itself as well*/
if(timer->repeat_count == 0) { /*The repeat count is over, delete the timer*/
TIMER_TRACE("deleting timer with %p callback because the repeat count is over", timer->timer_cb);
lv_timer_del(timer);
}
}
return exec; return exec;
} }

View File

@ -63,7 +63,7 @@ void _lv_timer_core_init(void);
//! @cond Doxygen_Suppress //! @cond Doxygen_Suppress
/** /**
* Call it periodically to handle lv_timers. * Call it periodically to handle lv_timers.
* @return time till it needs to be run next (in ms) * @return time till it needs to be run next (in ms)
*/ */
LV_ATTRIBUTE_TIMER_HANDLER uint32_t lv_timer_handler(void); LV_ATTRIBUTE_TIMER_HANDLER uint32_t lv_timer_handler(void);
@ -97,7 +97,6 @@ void lv_timer_del(lv_timer_t * timer);
/** /**
* Pause/resume a timer. * Pause/resume a timer.
* @param timer pointer to an lv_timer * @param timer pointer to an lv_timer
* @param pause true: pause the timer; false: resume
*/ */
void lv_timer_pause(lv_timer_t * timer); void lv_timer_pause(lv_timer_t * timer);