From 9ba4653243ee6bcdd9e80bc56e0e10c53b8497f2 Mon Sep 17 00:00:00 2001 From: Mohamed ElShahawi Date: Sun, 17 Mar 2024 21:40:49 +0100 Subject: [PATCH] kernel: work_queue: make thread essential flag configurable Allow the creator of a work_queue instance to choose whether the work_queue thread should be marked as ESSENTIAL or not. Signed-off-by: Mohamed ElShahawi --- include/zephyr/kernel.h | 5 +++++ kernel/work.c | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/include/zephyr/kernel.h b/include/zephyr/kernel.h index da43eea977..6a3bd04c0a 100644 --- a/include/zephyr/kernel.h +++ b/include/zephyr/kernel.h @@ -4004,6 +4004,11 @@ struct k_work_queue_config { * control. */ bool no_yield; + + /** Control whether the work queue thread should be marked as + * essential thread. + */ + bool essential; }; /** @brief A structure used to hold work until it can be processed. */ diff --git a/kernel/work.c b/kernel/work.c index cf73bdbcab..1615c321f7 100644 --- a/kernel/work.c +++ b/kernel/work.c @@ -761,6 +761,10 @@ void k_work_queue_start(struct k_work_q *queue, k_thread_name_set(&queue->thread, cfg->name); } + if ((cfg != NULL) && (cfg->essential)) { + queue->thread.base.user_options |= K_ESSENTIAL; + } + k_thread_start(&queue->thread); SYS_PORT_TRACING_OBJ_FUNC_EXIT(k_work_queue, start, queue);