XenevaOS
Loading...
Searching...
No Matches
workqueue.h
Go to the documentation of this file.
1#ifndef __WORKQUEUE_H__
2#define __WORKQUEUE_H__
3
4#include <linux/timer.h>
5
6typedef void (*work_func_t)(struct work_struct* work);
7
8struct work_struct {
10 void* data; /* your private context */
12};
13
15 const char* name;
16 /* stub — single threaded on bare metal */
17};
18
19/* Init */
20#define INIT_WORK(_work, _func) do { \
21 (_work)->func = (_func); \
22 (_work)->pending = 0; \
23 (_work)->data = NULL; \
24} while (0)
25
26/* On bare metal — just call it directly */
27#define schedule_work(work) \
28 do { if ((work)->func) (work)->func(work); } while (0)
29
30#define queue_work(wq, work) \
31 do { if ((work)->func) (work)->func(work); } while (0)
32
33#define flush_work(work) do {} while (0)
34#define cancel_work_sync(work) do {} while (0)
35#define flush_workqueue(wq) do {} while (0)
36#define destroy_workqueue(wq) do {} while (0)
37
38static inline struct workqueue_struct*
39alloc_ordered_workqueue(const char* name, int flags) {
40 static struct workqueue_struct wq;
41 wq.name = name;
42 return &wq;
43}
44
45#define create_singlethread_workqueue(name) \
46 alloc_ordered_workqueue(name, 0)
47
48/* Get owning struct back from work pointer */
49#define container_of_work(ptr, type, member) \
50 container_of(ptr, type, member)
51
57
58#define INIT_DELAYED_WORK(_dwork, _func) do { \
59 INIT_WORK(&(_dwork)->work, _func); \
60 timer_setup(&(_dwork)->timer, NULL, 0); \
61 (_dwork)->wq = NULL; \
62} while (0)
63
64/* On bare metal — execute immediately for bring-up */
65static inline bool schedule_delayed_work(struct delayed_work* dwork,
66 unsigned long delay) {
67 if (dwork->work.func)
68 dwork->work.func(&dwork->work);
69 return true;
70}
71
72static inline bool queue_delayed_work(struct workqueue_struct* wq,
73 struct delayed_work* dwork,
74 unsigned long delay) {
75 if (dwork->work.func)
76 dwork->work.func(&dwork->work);
77 return true;
78}
79
80static inline bool cancel_delayed_work(struct delayed_work* dwork) {
81 del_timer(&dwork->timer);
82 dwork->work.pending = 0;
83 return true;
84}
85
86static inline bool cancel_delayed_work_sync(struct delayed_work* dwork) {
87 return cancel_delayed_work(dwork);
88}
89
90static inline bool flush_delayed_work(struct delayed_work* dwork) {
91 return true;
92}
93
94/* Get owning struct from delayed_work pointer */
95#define to_delayed_work(ptr) \
96 container_of(ptr, struct delayed_work, work)
97#endif
Definition workqueue.h:52
struct timer_list timer
Definition workqueue.h:54
struct work_struct work
Definition workqueue.h:53
struct workqueue_struct * wq
Definition workqueue.h:55
Definition timer.h:1
Definition workqueue.h:8
int pending
Definition workqueue.h:11
void * data
Definition workqueue.h:10
work_func_t func
Definition workqueue.h:9
Definition workqueue.h:14
const char * name
Definition workqueue.h:15
void(* work_func_t)(struct work_struct *work)
Definition workqueue.h:6