1 /*
2 * Copyright (c) 2006-2018, RT-Thread Development Team
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 *
6 * Change Logs:
7 * Date Author Notes
8 */
9 #ifndef WORKQUEUE_H__
10 #define WORKQUEUE_H__
11
12 #include <rtthread.h>
13
14 /* workqueue implementation */
15 struct rt_workqueue
16 {
17 rt_list_t work_list;
18 struct rt_work *work_current; /* current work */
19
20 struct rt_semaphore sem;
21 rt_thread_t work_thread;
22 };
23
24 struct rt_work
25 {
26 rt_list_t list;
27
28 void (*work_func)(struct rt_work* work, void* work_data);
29 void *work_data;
30 };
31
32 #ifdef RT_USING_HEAP
33 /**
34 * WorkQueue for DeviceDriver
35 */
36 struct rt_workqueue *rt_workqueue_create(const char* name, rt_uint16_t stack_size, rt_uint8_t priority);
37 rt_err_t rt_workqueue_destroy(struct rt_workqueue* queue);
38 rt_err_t rt_workqueue_dowork(struct rt_workqueue* queue, struct rt_work* work);
39 rt_err_t rt_workqueue_cancel_work(struct rt_workqueue* queue, struct rt_work* work);
40 rt_err_t rt_workqueue_cancel_work_sync(struct rt_workqueue* queue, struct rt_work* work);
41
rt_work_init(struct rt_work * work,void (* work_func)(struct rt_work * work,void * work_data),void * work_data)42 rt_inline void rt_work_init(struct rt_work* work, void (*work_func)(struct rt_work* work, void* work_data),
43 void* work_data)
44 {
45 rt_list_init(&(work->list));
46 work->work_func = work_func;
47 work->work_data = work_data;
48 }
49 #endif
50
51 #endif
52
53