MCPcopy Index your code
hub / github.com/RT-Thread/rt-thread / _timer_check

Function _timer_check

src/timer.c:488–553  ·  view source on GitHub ↗

* @brief This function will check timer list, if a timeout event happens, * the corresponding timeout function will be invoked. * * @param timer_list The timer list to check. * @param lock The lock for the timer list. */

Source from the content-addressed store, hash-verified

486 * @param lock The lock for the timer list.
487 */
488static void _timer_check(rt_list_t *timer_list, struct rt_spinlock *lock)
489{
490 struct rt_timer *t;
491 rt_tick_t current_tick;
492 rt_base_t level;
493 rt_list_t list;
494
495 level = rt_spin_lock_irqsave(lock);
496
497 current_tick = rt_tick_get();
498
499 rt_list_init(&list);
500
501 while (!rt_list_isempty(&timer_list[RT_TIMER_SKIP_LIST_LEVEL - 1]))
502 {
503 t = rt_list_entry(timer_list[RT_TIMER_SKIP_LIST_LEVEL - 1].next,
504 struct rt_timer, row[RT_TIMER_SKIP_LIST_LEVEL - 1]);
505
506 /* re-get tick */
507 current_tick = rt_tick_get();
508
509 /*
510 * It supposes that the new tick shall less than the half duration of
511 * tick max.
512 */
513 if ((current_tick - t->timeout_tick) < RT_TICK_MAX / 2)
514 {
515 RT_OBJECT_HOOK_CALL(rt_timer_enter_hook, (t));
516
517 /* remove timer from timer list firstly */
518 _timer_remove(t);
519 if (!(t->parent.flag & RT_TIMER_FLAG_PERIODIC))
520 {
521 t->parent.flag &= ~RT_TIMER_FLAG_ACTIVATED;
522 }
523
524 /* add timer to temporary list */
525 rt_list_insert_after(&list, &(t->row[RT_TIMER_SKIP_LIST_LEVEL - 1]));
526
527 rt_spin_unlock_irqrestore(lock, level);
528
529 /* call timeout function */
530 t->timeout_func(t->parameter);
531
532 RT_OBJECT_HOOK_CALL(rt_timer_exit_hook, (t));
533
534 level = rt_spin_lock_irqsave(lock);
535
536 /* Check whether the timer object is detached or started again */
537 if (rt_list_isempty(&list))
538 {
539 continue;
540 }
541 rt_list_remove(&(t->row[RT_TIMER_SKIP_LIST_LEVEL - 1]));
542 if ((t->parent.flag & RT_TIMER_FLAG_PERIODIC) &&
543 (t->parent.flag & RT_TIMER_FLAG_ACTIVATED))
544 {
545 /* start it */

Callers 2

rt_timer_checkFunction · 0.85
_timer_thread_entryFunction · 0.85

Calls 9

rt_tick_getFunction · 0.85
rt_list_initFunction · 0.85
rt_list_isemptyFunction · 0.85
_timer_removeFunction · 0.85
rt_list_insert_afterFunction · 0.85
rt_list_removeFunction · 0.85
rt_spin_lock_irqsaveFunction · 0.70
_timer_startFunction · 0.70

Tested by

no test coverage detected