kernel: Add assert to detect negative timeouts

Add assert when negative (except K_FOREVER) is passed as timeout.
Add negative timeout correction to 0.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
This commit is contained in:
Krzysztof Chruscinski 2019-11-07 19:32:34 +01:00 committed by Andrew Boie
commit f831929cb5

View file

@ -368,7 +368,16 @@ static void pend(struct k_thread *thread, _wait_q_t *wait_q, s32_t timeout)
}
if (timeout != K_FOREVER) {
s32_t ticks = _TICK_ALIGN + k_ms_to_ticks_ceil32(timeout);
s32_t ticks;
__ASSERT(timeout >= 0,
"Only non-negative values are accepted.");
if (timeout < 0) {
timeout = 0;
}
ticks = _TICK_ALIGN + k_ms_to_ticks_ceil32(timeout);
z_add_thread_timeout(thread, ticks);
}