From d9aa4148318aa7406a51fa15f77e329c7c0ee08a Mon Sep 17 00:00:00 2001 From: Flavio Ceolin Date: Mon, 23 Aug 2021 14:33:40 -0700 Subject: [PATCH] kernel: work_q: Add an init function k_work_queue_start receives a struct that is expected to be uninitialized (zeroed). Otherwise the behavior is undefined. Following the Zephyr semantics, this pr introduce a new init function for this struct. Fixes #36865 Signed-off-by: Flavio Ceolin --- include/kernel.h | 11 +++++++++++ kernel/work.c | 11 +++++++++++ 2 files changed, 22 insertions(+) diff --git a/include/kernel.h b/include/kernel.h index a4dca2bce3f..ec037962ea1 100644 --- a/include/kernel.h +++ b/include/kernel.h @@ -3045,6 +3045,17 @@ int k_work_cancel(struct k_work *work); */ bool k_work_cancel_sync(struct k_work *work, struct k_work_sync *sync); +/** @brief Initialize a work queue structure. + * + * This must be invoked before starting a work queue structure for the first time. + * It need not be invoked again on the same work queue structure. + * + * @funcprops \isr_ok + * + * @param queue the queue structure to be initialized. + */ +void k_work_queue_init(struct k_work_q *queue); + /** @brief Initialize a work queue. * * This configures the work queue thread and starts it running. The function diff --git a/kernel/work.c b/kernel/work.c index d3f34db8501..6682b97a07e 100644 --- a/kernel/work.c +++ b/kernel/work.c @@ -676,6 +676,17 @@ static void work_queue_main(void *workq_ptr, void *p2, void *p3) } } +void k_work_queue_init(struct k_work_q *queue) +{ + __ASSERT_NO_MSG(queue != NULL); + + *queue = (struct k_work_q) { + .flags = 0, + }; + + SYS_PORT_TRACING_OBJ_INIT(k_work_queue, queue); +} + void k_work_queue_start(struct k_work_q *queue, k_thread_stack_t *stack, size_t stack_size,