1 /* long_work.c - Workqueue intended for long-running operations. */
2 
3 /*
4  * Copyright (c) 2022 Nordic Semiconductor ASA
5  *
6  * SPDX-License-Identifier: Apache-2.0
7  */
8 #include <zephyr/kernel.h>
9 #include <zephyr/init.h>
10 
11 K_THREAD_STACK_DEFINE(bt_lw_stack_area, CONFIG_BT_LONG_WQ_STACK_SIZE);
12 static struct k_work_q bt_long_wq;
13 
bt_long_wq_schedule(struct k_work_delayable * dwork,k_timeout_t timeout)14 int bt_long_wq_schedule(struct k_work_delayable *dwork, k_timeout_t timeout)
15 {
16 	return k_work_schedule_for_queue(&bt_long_wq, dwork, timeout);
17 }
18 
bt_long_wq_reschedule(struct k_work_delayable * dwork,k_timeout_t timeout)19 int bt_long_wq_reschedule(struct k_work_delayable *dwork, k_timeout_t timeout)
20 {
21 	return k_work_reschedule_for_queue(&bt_long_wq, dwork, timeout);
22 }
23 
bt_long_wq_submit(struct k_work * work)24 int bt_long_wq_submit(struct k_work *work)
25 {
26 	return k_work_submit_to_queue(&bt_long_wq, work);
27 }
28 
long_wq_init(void)29 static int long_wq_init(void)
30 {
31 
32 	const struct k_work_queue_config cfg = {.name = "BT LW WQ"};
33 
34 	k_work_queue_init(&bt_long_wq);
35 
36 	k_work_queue_start(&bt_long_wq, bt_lw_stack_area,
37 			   K_THREAD_STACK_SIZEOF(bt_lw_stack_area),
38 			   CONFIG_BT_LONG_WQ_PRIO, &cfg);
39 
40 	return 0;
41 }
42 
43 SYS_INIT(long_wq_init, POST_KERNEL, CONFIG_BT_LONG_WQ_INIT_PRIO);
44