Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | * workqueue.h --- work queue handling for Linux. | |
3 | */ | |
4 | ||
5 | #ifndef _LINUX_WORKQUEUE_H | |
6 | #define _LINUX_WORKQUEUE_H | |
7 | ||
8 | #include <linux/timer.h> | |
9 | #include <linux/linkage.h> | |
10 | #include <linux/bitops.h> | |
a08727ba | 11 | #include <asm/atomic.h> |
1da177e4 LT |
12 | |
13 | struct workqueue_struct; | |
14 | ||
65f27f38 DH |
15 | struct work_struct; |
16 | typedef void (*work_func_t)(struct work_struct *work); | |
6bb49e59 | 17 | |
a08727ba LT |
18 | /* |
19 | * The first word is the work queue pointer and the flags rolled into | |
20 | * one | |
21 | */ | |
22 | #define work_data_bits(work) ((unsigned long *)(&(work)->data)) | |
23 | ||
1da177e4 | 24 | struct work_struct { |
a08727ba | 25 | atomic_long_t data; |
365970a1 DH |
26 | #define WORK_STRUCT_PENDING 0 /* T if work item pending execution */ |
27 | #define WORK_STRUCT_FLAG_MASK (3UL) | |
28 | #define WORK_STRUCT_WQ_DATA_MASK (~WORK_STRUCT_FLAG_MASK) | |
1da177e4 | 29 | struct list_head entry; |
6bb49e59 | 30 | work_func_t func; |
52bad64d DH |
31 | }; |
32 | ||
23b2e599 | 33 | #define WORK_DATA_INIT() ATOMIC_LONG_INIT(0) |
a08727ba | 34 | |
52bad64d DH |
35 | struct delayed_work { |
36 | struct work_struct work; | |
1da177e4 LT |
37 | struct timer_list timer; |
38 | }; | |
39 | ||
1fa44eca JB |
40 | struct execute_work { |
41 | struct work_struct work; | |
42 | }; | |
43 | ||
65f27f38 | 44 | #define __WORK_INITIALIZER(n, f) { \ |
23b2e599 ON |
45 | .data = WORK_DATA_INIT(), \ |
46 | .entry = { &(n).entry, &(n).entry }, \ | |
65f27f38 DH |
47 | .func = (f), \ |
48 | } | |
49 | ||
50 | #define __DELAYED_WORK_INITIALIZER(n, f) { \ | |
51 | .work = __WORK_INITIALIZER((n).work, (f)), \ | |
52 | .timer = TIMER_INITIALIZER(NULL, 0, 0), \ | |
53 | } | |
54 | ||
65f27f38 DH |
55 | #define DECLARE_WORK(n, f) \ |
56 | struct work_struct n = __WORK_INITIALIZER(n, f) | |
57 | ||
65f27f38 DH |
58 | #define DECLARE_DELAYED_WORK(n, f) \ |
59 | struct delayed_work n = __DELAYED_WORK_INITIALIZER(n, f) | |
60 | ||
1da177e4 | 61 | /* |
65f27f38 | 62 | * initialize a work item's function pointer |
1da177e4 | 63 | */ |
65f27f38 | 64 | #define PREPARE_WORK(_work, _func) \ |
1da177e4 | 65 | do { \ |
52bad64d | 66 | (_work)->func = (_func); \ |
1da177e4 LT |
67 | } while (0) |
68 | ||
65f27f38 DH |
69 | #define PREPARE_DELAYED_WORK(_work, _func) \ |
70 | PREPARE_WORK(&(_work)->work, (_func)) | |
52bad64d | 71 | |
1da177e4 | 72 | /* |
52bad64d | 73 | * initialize all of a work item in one go |
a08727ba LT |
74 | * |
75 | * NOTE! No point in using "atomic_long_set()": useing a direct | |
76 | * assignment of the work data initializer allows the compiler | |
77 | * to generate better code. | |
1da177e4 | 78 | */ |
23b2e599 | 79 | #define INIT_WORK(_work, _func) \ |
65f27f38 | 80 | do { \ |
23b2e599 | 81 | (_work)->data = (atomic_long_t) WORK_DATA_INIT(); \ |
65f27f38 DH |
82 | INIT_LIST_HEAD(&(_work)->entry); \ |
83 | PREPARE_WORK((_work), (_func)); \ | |
84 | } while (0) | |
85 | ||
86 | #define INIT_DELAYED_WORK(_work, _func) \ | |
87 | do { \ | |
88 | INIT_WORK(&(_work)->work, (_func)); \ | |
89 | init_timer(&(_work)->timer); \ | |
52bad64d DH |
90 | } while (0) |
91 | ||
28287033 VP |
92 | #define INIT_DELAYED_WORK_DEFERRABLE(_work, _func) \ |
93 | do { \ | |
94 | INIT_WORK(&(_work)->work, (_func)); \ | |
95 | init_timer_deferrable(&(_work)->timer); \ | |
96 | } while (0) | |
97 | ||
365970a1 DH |
98 | /** |
99 | * work_pending - Find out whether a work item is currently pending | |
100 | * @work: The work item in question | |
101 | */ | |
102 | #define work_pending(work) \ | |
a08727ba | 103 | test_bit(WORK_STRUCT_PENDING, work_data_bits(work)) |
365970a1 DH |
104 | |
105 | /** | |
106 | * delayed_work_pending - Find out whether a delayable work item is currently | |
107 | * pending | |
108 | * @work: The work item in question | |
109 | */ | |
0221872a LT |
110 | #define delayed_work_pending(w) \ |
111 | work_pending(&(w)->work) | |
365970a1 | 112 | |
65f27f38 | 113 | /** |
23b2e599 ON |
114 | * work_clear_pending - for internal use only, mark a work item as not pending |
115 | * @work: The work item in question | |
65f27f38 | 116 | */ |
23b2e599 | 117 | #define work_clear_pending(work) \ |
a08727ba | 118 | clear_bit(WORK_STRUCT_PENDING, work_data_bits(work)) |
65f27f38 | 119 | |
52bad64d | 120 | |
1da177e4 | 121 | extern struct workqueue_struct *__create_workqueue(const char *name, |
341a5958 RW |
122 | int singlethread, |
123 | int freezeable); | |
124 | #define create_workqueue(name) __create_workqueue((name), 0, 0) | |
e3dfd296 | 125 | #define create_freezeable_workqueue(name) __create_workqueue((name), 1, 1) |
341a5958 | 126 | #define create_singlethread_workqueue(name) __create_workqueue((name), 1, 0) |
1da177e4 LT |
127 | |
128 | extern void destroy_workqueue(struct workqueue_struct *wq); | |
129 | ||
130 | extern int FASTCALL(queue_work(struct workqueue_struct *wq, struct work_struct *work)); | |
28e53bdd ON |
131 | extern int FASTCALL(queue_delayed_work(struct workqueue_struct *wq, |
132 | struct delayed_work *work, unsigned long delay)); | |
7a6bc1cd | 133 | extern int queue_delayed_work_on(int cpu, struct workqueue_struct *wq, |
28e53bdd ON |
134 | struct delayed_work *work, unsigned long delay); |
135 | ||
1da177e4 | 136 | extern void FASTCALL(flush_workqueue(struct workqueue_struct *wq)); |
28e53bdd | 137 | extern void flush_scheduled_work(void); |
1da177e4 LT |
138 | |
139 | extern int FASTCALL(schedule_work(struct work_struct *work)); | |
28e53bdd ON |
140 | extern int FASTCALL(schedule_delayed_work(struct delayed_work *work, |
141 | unsigned long delay)); | |
142 | extern int schedule_delayed_work_on(int cpu, struct delayed_work *work, | |
143 | unsigned long delay); | |
65f27f38 | 144 | extern int schedule_on_each_cpu(work_func_t func); |
1da177e4 LT |
145 | extern int current_is_keventd(void); |
146 | extern int keventd_up(void); | |
147 | ||
148 | extern void init_workqueues(void); | |
65f27f38 | 149 | int execute_in_process_context(work_func_t fn, struct execute_work *); |
1da177e4 | 150 | |
1f1f642e | 151 | extern int cancel_work_sync(struct work_struct *work); |
28e53bdd | 152 | |
1da177e4 LT |
153 | /* |
154 | * Kill off a pending schedule_delayed_work(). Note that the work callback | |
071b6386 ON |
155 | * function may still be running on return from cancel_delayed_work(), unless |
156 | * it returns 1 and the work doesn't re-arm itself. Run flush_workqueue() or | |
28e53bdd | 157 | * cancel_work_sync() to wait on it. |
1da177e4 | 158 | */ |
52bad64d | 159 | static inline int cancel_delayed_work(struct delayed_work *work) |
1da177e4 LT |
160 | { |
161 | int ret; | |
162 | ||
223a10a9 | 163 | ret = del_timer_sync(&work->timer); |
1da177e4 | 164 | if (ret) |
23b2e599 | 165 | work_clear_pending(&work->work); |
1da177e4 LT |
166 | return ret; |
167 | } | |
168 | ||
1f1f642e | 169 | extern int cancel_delayed_work_sync(struct delayed_work *work); |
1634c48f | 170 | |
f5a421a4 | 171 | /* Obsolete. use cancel_delayed_work_sync() */ |
1634c48f ON |
172 | static inline |
173 | void cancel_rearming_delayed_workqueue(struct workqueue_struct *wq, | |
174 | struct delayed_work *work) | |
175 | { | |
f5a421a4 ON |
176 | cancel_delayed_work_sync(work); |
177 | } | |
178 | ||
179 | /* Obsolete. use cancel_delayed_work_sync() */ | |
180 | static inline | |
181 | void cancel_rearming_delayed_work(struct delayed_work *work) | |
182 | { | |
183 | cancel_delayed_work_sync(work); | |
1634c48f ON |
184 | } |
185 | ||
1da177e4 | 186 | #endif |