zephyr/kernel/system_work_q.c
Anas Nashif 2d47a9b79c kernel: system_work_q: register init via kernel init hook
Replace the system work queue's SYS_INIT (POST_KERNEL) with a
K_KERNEL_INIT_POST() hook. The init function and its hook entry live in
this translation unit, which is linked only when something references the
system work queue (e.g. k_sys_work_q), so an image that never uses it
neither links this code nor runs this init -- the same pay-per-use
behavior SYS_INIT gave, now without the init level/priority.

The hook runs before POST_KERNEL device init so that drivers initialized
there may submit work to the queue.

Assisted-by: Claude:claude-opus-4-8
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2026-07-06 15:10:55 -04:00

41 lines
1 KiB
C

/*
* Copyright (c) 2016 Wind River Systems, Inc.
* Copyright (c) 2016 Intel Corporation
*
* SPDX-License-Identifier: Apache-2.0
*/
/**
* @file
*
* System workqueue.
*/
#include <zephyr/kernel.h>
#include <kernel_internal.h>
static K_KERNEL_STACK_DEFINE(sys_work_q_stack,
CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE);
struct k_work_q k_sys_work_q;
static void sys_work_q_init(void)
{
static const struct k_work_queue_config cfg = {
.name = "sysworkq",
.no_yield = IS_ENABLED(CONFIG_SYSTEM_WORKQUEUE_NO_YIELD),
.essential = true,
.work_timeout_ms = CONFIG_SYSTEM_WORKQUEUE_WORK_TIMEOUT_MS,
};
k_work_queue_start(&k_sys_work_q,
sys_work_q_stack,
K_KERNEL_STACK_SIZEOF(sys_work_q_stack),
CONFIG_SYSTEM_WORKQUEUE_PRIORITY, &cfg);
}
/* Registered into the kernel post-init section. The entry lives in this TU,
* so it (and this init) is linked only when something references the system
* work queue (e.g. k_sys_work_q), preserving pay-per-use linkage.
*/
K_KERNEL_INIT_POST(sys_work_q_init);