Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

timer: k_timer_start should be allowed to start start with duration = 0 #1073

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion kernel/include/timeout_q.h
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ static inline void _add_timeout(struct k_thread *thread,
_wait_q_t *wait_q,
s32_t timeout_in_ticks)
{
__ASSERT(timeout_in_ticks > 0, "");
__ASSERT(timeout_in_ticks >= 0, "");

timeout->delta_ticks_from_prev = timeout_in_ticks;
timeout->thread = thread;
Expand All @@ -207,6 +207,16 @@ static inline void _add_timeout(struct k_thread *thread,
_dump_timeout(timeout, 0);
_dump_timeout_q();

/* If timer is submitted to expire ASAP with
* timeout_in_ticks (duration) as zero value,
* then handle timeout immedately without going
* through timeout queue.
*/
if (!timeout_in_ticks) {
_handle_one_expired_timeout(timeout);
return;
}

s32_t *delta = &timeout->delta_ticks_from_prev;
struct _timeout *in_q;

Expand Down
4 changes: 2 additions & 2 deletions kernel/timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ void k_timer_start(struct k_timer *timer, s32_t duration, s32_t period)
volatile s32_t period_in_ticks, duration_in_ticks;

period_in_ticks = _ms_to_ticks(period);
duration_in_ticks = _TICK_ALIGN + _ms_to_ticks(duration);
duration_in_ticks = _ms_to_ticks(duration);

unsigned int key = irq_lock();

Expand All @@ -123,8 +123,8 @@ void k_timer_start(struct k_timer *timer, s32_t duration, s32_t period)
}

timer->period = period_in_ticks;
_add_timeout(NULL, &timer->timeout, &timer->wait_q, duration_in_ticks);
timer->status = 0;
_add_timeout(NULL, &timer->timeout, &timer->wait_q, duration_in_ticks);
irq_unlock(key);
}

Expand Down