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 
9 #include <zephyr/autoconf.h>
10 #include <zephyr/kernel.h>
11 #include <zephyr/init.h>
12 #include <zephyr/kernel/thread_stack.h>
13 #include <zephyr/sys_clock.h>
14 
15 K_THREAD_STACK_DEFINE(bt_lw_stack_area, CONFIG_BT_LONG_WQ_STACK_SIZE);
16 static struct k_work_q bt_long_wq;
17 
bt_long_wq_schedule(struct k_work_delayable * dwork,k_timeout_t timeout)18 int bt_long_wq_schedule(struct k_work_delayable *dwork, k_timeout_t timeout)
19 {
20 	return k_work_schedule_for_queue(&bt_long_wq, dwork, timeout);
21 }
22 
bt_long_wq_reschedule(struct k_work_delayable * dwork,k_timeout_t timeout)23 int bt_long_wq_reschedule(struct k_work_delayable *dwork, k_timeout_t timeout)
24 {
25 	return k_work_reschedule_for_queue(&bt_long_wq, dwork, timeout);
26 }
27 
bt_long_wq_submit(struct k_work * work)28 int bt_long_wq_submit(struct k_work *work)
29 {
30 	return k_work_submit_to_queue(&bt_long_wq, work);
31 }
32 
long_wq_init(void)33 static int long_wq_init(void)
34 {
35 
36 	const struct k_work_queue_config cfg = {.name = "BT LW WQ"};
37 
38 	k_work_queue_init(&bt_long_wq);
39 
40 	k_work_queue_start(&bt_long_wq, bt_lw_stack_area,
41 			   K_THREAD_STACK_SIZEOF(bt_lw_stack_area),
42 			   CONFIG_BT_LONG_WQ_PRIO, &cfg);
43 
44 	return 0;
45 }
46 
47 SYS_INIT(long_wq_init, POST_KERNEL, CONFIG_BT_LONG_WQ_INIT_PRIO);
48