diff options
author | Allan Stephens <allan.stephens@windriver.com> | 2016-10-17 14:34:53 -0500 |
---|---|---|
committer | Benjamin Walsh <benjamin.walsh@windriver.com> | 2016-10-21 15:33:29 +0000 |
commit | 6c98c4d378749ec7516addc3cf3e81e95db109cc (patch) | |
tree | d4868bbb46afccf8a2c922894b51002b3c5976db /include | |
parent | 811d97c32022cb7a73e01550076646928b824617 (diff) |
unified: Ensure delays do not time out prematurely
Ensures that all APIs which accept a timeout value wait for at least
the specified amount of time, and do not time out prematurely.
* The kernel now waits for the next system clock tick to occur before
the timeout interval is considered to have started. (That is, the only
way to ensure a delay of N tick intervals is to wait for N+1 ticks
to occur.)
* Gets rid of ticks -> milliseconds -> ticks conversion in task_sleep()
and fiber_sleep() legacy APIs, since this introduces rounding that
-- coupled with the previous change -- can alter the number of ticks
being requested during the sleep operation.
* Corrects work queue API that was incorrectly shown to use a delay
measured in ticks, rather than milliseconds.
Change-Id: I8b04467237b24fb0364c8f344d872457418c18da
Signed-off-by: Allan Stephens <allan.stephens@windriver.com>
Diffstat (limited to 'include')
-rw-r--r-- | include/kernel.h | 13 | ||||
-rw-r--r-- | include/legacy.h | 9 |
2 files changed, 12 insertions, 10 deletions
diff --git a/include/kernel.h b/include/kernel.h index 2cc3cfed9..bb8852676 100644 --- a/include/kernel.h +++ b/include/kernel.h @@ -273,6 +273,9 @@ extern void *k_thread_custom_data_get(void); /* private internal time manipulation (users should never play with ticks) */ +/* added tick needed to account for tick in progress */ +#define _TICK_ALIGN 1 + static int64_t __ticks_to_ms(int64_t ticks) { #if CONFIG_SYS_CLOCK_EXISTS @@ -694,15 +697,15 @@ extern void k_delayed_work_init(struct k_delayed_work *work, * mutual exclusion mechanism. Such usage is not recommended and if necessary, * it should be explicitly done between the submitter and the handler. * - * @param work_q to schedule the work item + * @param work_q Workqueue to schedule the work item * @param work Delayed work item - * @param ticks Ticks to wait before scheduling the work item + * @param delay Delay before scheduling the work item (in milliseconds) * * @return 0 in case of success or negative value in case of error. */ extern int k_delayed_work_submit_to_queue(struct k_work_q *work_q, struct k_delayed_work *work, - int32_t ticks); + int32_t delay); /** * @brief Cancel a delayed work item @@ -749,9 +752,9 @@ static inline void k_work_submit(struct k_work *work) * unexpected behavior. */ static inline int k_delayed_work_submit(struct k_delayed_work *work, - int ticks) + int32_t delay) { - return k_delayed_work_submit_to_queue(&k_sys_work_q, work, ticks); + return k_delayed_work_submit_to_queue(&k_sys_work_q, work, delay); } #endif /* CONFIG_SYS_CLOCK_EXISTS */ diff --git a/include/legacy.h b/include/legacy.h index 2d1d48206..4ae1469d5 100644 --- a/include/legacy.h +++ b/include/legacy.h @@ -138,17 +138,16 @@ fiber_delayed_start(char *stack, unsigned int stack_size_in_bytes, #define fiber_yield k_yield #define fiber_abort() k_thread_abort(k_current_get()) -static inline void fiber_sleep(int32_t timeout) -{ - k_sleep(_ticks_to_ms(timeout)); -} + +extern void _legacy_sleep(int32_t ticks); +#define fiber_sleep _legacy_sleep +#define task_sleep _legacy_sleep #define fiber_wakeup k_wakeup #define isr_fiber_wakeup k_wakeup #define fiber_fiber_wakeup k_wakeup #define task_fiber_wakeup k_wakeup -#define task_sleep fiber_sleep #define task_yield k_yield #define task_priority_set(task, prio) k_thread_priority_set(task, (int)prio) #define task_entry_set(task, entry) \ |