diff --git a/include/kernel.h b/include/kernel.h index fa183388211..2edd113527a 100644 --- a/include/kernel.h +++ b/include/kernel.h @@ -873,9 +873,6 @@ __syscall void k_thread_start(k_tid_t thread); /* timeout has timed out and is not on _timeout_q anymore */ #define _EXPIRED (-2) -/* timeout is not in use */ -#define _INACTIVE (-1) - struct _static_thread_data { struct k_thread *init_thread; k_thread_stack_t *init_stack; @@ -1334,7 +1331,7 @@ struct k_timer { #define _K_TIMER_INITIALIZER(obj, expiry, stop) \ { \ - .timeout.dticks = _INACTIVE, \ + .timeout.dticks = 0, \ .timeout.fn = _timer_expiration_handler, \ .wait_q = _WAIT_Q_INIT(&obj.wait_q), \ .expiry_fn = expiry, \ diff --git a/kernel/include/ksched.h b/kernel/include/ksched.h index f44e88da270..f44df94894d 100644 --- a/kernel/include/ksched.h +++ b/kernel/include/ksched.h @@ -8,6 +8,7 @@ #define ZEPHYR_KERNEL_INCLUDE_KSCHED_H_ #include +#include #include #include @@ -83,11 +84,7 @@ static inline int _is_thread_prevented_from_running(struct k_thread *thread) static inline bool _is_thread_timeout_active(struct k_thread *thread) { -#ifdef CONFIG_SYS_CLOCK_EXISTS - return thread->base.timeout.dticks != _INACTIVE; -#else - return false; -#endif + return !_is_inactive_timeout(&thread->base.timeout); } static inline bool _is_thread_ready(struct k_thread *thread) diff --git a/kernel/include/timeout_q.h b/kernel/include/timeout_q.h index 75d3aa33a0a..3438957f0ff 100644 --- a/kernel/include/timeout_q.h +++ b/kernel/include/timeout_q.h @@ -23,13 +23,17 @@ extern "C" { static inline void _init_timeout(struct _timeout *t, _timeout_func_t fn) { sys_dnode_init(&t->node); - t->dticks = _INACTIVE; } void _add_timeout(struct _timeout *to, _timeout_func_t fn, s32_t ticks); int _abort_timeout(struct _timeout *to); +static inline bool _is_inactive_timeout(struct _timeout *t) +{ + return !sys_dnode_is_linked(&t->node); +} + static inline void _init_thread_timeout(struct _thread_base *thread_base) { _init_timeout(&thread_base->timeout, NULL); @@ -59,6 +63,7 @@ s32_t z_timeout_remaining(struct _timeout *timeout); #define _init_thread_timeout(t) do {} while (0) #define _add_thread_timeout(th, to) do {} while (0 && (void *)to && (void *)th) #define _abort_thread_timeout(t) (0) +#define _is_inactive_timeout(t) 0 #define _get_next_timeout_expiry() (K_FOREVER) #define z_set_timeout_expiry(t, i) do {} while (0) diff --git a/kernel/sched.c b/kernel/sched.c index d704141ca32..e757624ee0e 100644 --- a/kernel/sched.c +++ b/kernel/sched.c @@ -896,7 +896,7 @@ void _impl_k_wakeup(k_tid_t thread) return; } - if (_abort_thread_timeout(thread) == _INACTIVE) { + if (_abort_thread_timeout(thread) < 0) { irq_unlock(key); return; } diff --git a/kernel/timeout.c b/kernel/timeout.c index 4cd4c05d1f8..2c4db74dab1 100644 --- a/kernel/timeout.c +++ b/kernel/timeout.c @@ -51,7 +51,6 @@ static void remove_timeout(struct _timeout *t) } sys_dlist_remove(&t->node); - t->dticks = _INACTIVE; } static s32_t elapsed(void) @@ -75,7 +74,7 @@ static s32_t next_timeout(void) void _add_timeout(struct _timeout *to, _timeout_func_t fn, s32_t ticks) { - __ASSERT(to->dticks < 0, ""); + __ASSERT(!sys_dnode_is_linked(&to->node), ""); to->fn = fn; ticks = max(1, ticks); @@ -107,7 +106,7 @@ void _add_timeout(struct _timeout *to, _timeout_func_t fn, s32_t ticks) int _abort_timeout(struct _timeout *to) { - int ret = _INACTIVE; + int ret = -EINVAL; LOCKED(&timeout_lock) { if (sys_dnode_is_linked(&to->node)) { @@ -123,7 +122,7 @@ s32_t z_timeout_remaining(struct _timeout *timeout) { s32_t ticks = 0; - if (timeout->dticks == _INACTIVE) { + if (_is_inactive_timeout(timeout)) { return 0; } diff --git a/kernel/timer.c b/kernel/timer.c index 544c5b1731f..ce49859b732 100644 --- a/kernel/timer.c +++ b/kernel/timer.c @@ -150,7 +150,7 @@ Z_SYSCALL_HANDLER(k_timer_start, timer, duration_p, period_p) void _impl_k_timer_stop(struct k_timer *timer) { unsigned int key = irq_lock(); - bool inactive = (_abort_timeout(&timer->timeout) == _INACTIVE); + int inactive = _abort_timeout(&timer->timeout) != 0; irq_unlock(key); @@ -203,7 +203,7 @@ u32_t _impl_k_timer_status_sync(struct k_timer *timer) u32_t result = timer->status; if (result == 0) { - if (timer->timeout.dticks != _INACTIVE) { + if (!_is_inactive_timeout(&timer->timeout)) { /* wait for timer to expire or stop */ (void)_pend_current_thread(key, &timer->wait_q, K_FOREVER);