Skip to content

Commit d9aa414

Browse files
Flavio Ceolinnashif
authored andcommitted
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 <[email protected]>
1 parent fcf7209 commit d9aa414

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

include/kernel.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3045,6 +3045,17 @@ int k_work_cancel(struct k_work *work);
30453045
*/
30463046
bool k_work_cancel_sync(struct k_work *work, struct k_work_sync *sync);
30473047

3048+
/** @brief Initialize a work queue structure.
3049+
*
3050+
* This must be invoked before starting a work queue structure for the first time.
3051+
* It need not be invoked again on the same work queue structure.
3052+
*
3053+
* @funcprops \isr_ok
3054+
*
3055+
* @param queue the queue structure to be initialized.
3056+
*/
3057+
void k_work_queue_init(struct k_work_q *queue);
3058+
30483059
/** @brief Initialize a work queue.
30493060
*
30503061
* This configures the work queue thread and starts it running. The function

kernel/work.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -676,6 +676,17 @@ static void work_queue_main(void *workq_ptr, void *p2, void *p3)
676676
}
677677
}
678678

679+
void k_work_queue_init(struct k_work_q *queue)
680+
{
681+
__ASSERT_NO_MSG(queue != NULL);
682+
683+
*queue = (struct k_work_q) {
684+
.flags = 0,
685+
};
686+
687+
SYS_PORT_TRACING_OBJ_INIT(k_work_queue, queue);
688+
}
689+
679690
void k_work_queue_start(struct k_work_q *queue,
680691
k_thread_stack_t *stack,
681692
size_t stack_size,

0 commit comments

Comments
 (0)