RT-Thread / RT-Thread/rt-thread

rt_timer_list_next_timeout() may return error?

Open
#4,309 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

discussion
Dominant language
C
Stars
12.2k
Forks
5.4k
Avg merge
4d 12h
Merged PRs (30d)
40

Description

If a timer has a timeout tick 0xFFFFFFFF(RT_TICK_MAX), the timer thread will suspend itself. And if the rt_tick now is 0xFFFFFFFF(RT_TICK_MAX), timer callback should be called immediately.


  /* the fist timer always in the last row */
  static rt_tick_t rt_timer_list_next_timeout(rt_list_t timer_list[])
  {
      struct rt_timer *timer;
      register rt_base_t level;
      rt_tick_t timeout_tick = RT_TICK_MAX;
  
      /* disable interrupt */
      level = rt_hw_interrupt_disable();
  
      if (!rt_list_isempty(&timer_list[RT_TIMER_SKIP_LIST_LEVEL - 1]))
      {
          timer = rt_list_entry(timer_list[RT_TIMER_SKIP_LIST_LEVEL - 1].next,
                                struct rt_timer, row[RT_TIMER_SKIP_LIST_LEVEL - 1]);
          timeout_tick = timer->timeout_tick;
      }
  
      /* enable interrupt */
      rt_hw_interrupt_enable(level);
  
      return timeout_tick;
  }


        /* get the next timeout tick */
        next_timeout = rt_timer_list_next_timeout(rt_soft_timer_list);
        if (next_timeout == RT_TICK_MAX)
        {
            /* no software timer exist, suspend self. */
            rt_thread_suspend(rt_thread_self());
            rt_schedule();
        }

Is that OK?

I suppose that the API should be "rt_err_t rt_timer_list_next_timeout(rt_list_t timer_list[], rt_tick_t *timeout_tick) " instead,

Thanks.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by inspecting rt_timer_list_next_timeout() and the software timer thread code shown in the issue. Trace the RT_TICK_MAX cases when a timer exists and when the current tick reaches that value, then determine the expected callback and suspension behavior. Done means the edge case is handled consistently and the API behavior is clearly validated.

Written by the indexing model from the issue text.

Assessment

Tech stack
c
Domain
embedded-iot, operating-systems
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.