]>
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) | |
125 | #define create_freezeable_workqueue(name) __create_workqueue((name), 0, 1) | |
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)); | |
52bad64d | 131 | extern int FASTCALL(queue_delayed_work(struct workqueue_struct *wq, struct delayed_work *work, unsigned long delay)); |
7a6bc1cd | 132 | extern int queue_delayed_work_on(int cpu, struct workqueue_struct *wq, |
52bad64d | 133 | struct delayed_work *work, unsigned long delay); |
1da177e4 | 134 | extern void FASTCALL(flush_workqueue(struct workqueue_struct *wq)); |
b89deed3 ON |
135 | extern void flush_work(struct workqueue_struct *wq, struct work_struct *work); |
136 | extern void flush_work_keventd(struct work_struct *work); | |
1da177e4 LT |
137 | |
138 | extern int FASTCALL(schedule_work(struct work_struct *work)); | |
52bad64d | 139 | extern int FASTCALL(schedule_delayed_work(struct delayed_work *work, unsigned long delay)); |
1da177e4 | 140 | |
52bad64d | 141 | extern int schedule_delayed_work_on(int cpu, struct delayed_work *work, unsigned long delay); |
65f27f38 | 142 | extern int schedule_on_each_cpu(work_func_t func); |
1da177e4 LT |
143 | extern void flush_scheduled_work(void); |
144 | extern int current_is_keventd(void); | |
145 | extern int keventd_up(void); | |
146 | ||
147 | extern void init_workqueues(void); | |
65f27f38 | 148 | int execute_in_process_context(work_func_t fn, struct execute_work *); |
1da177e4 LT |
149 | |
150 | /* | |
151 | * Kill off a pending schedule_delayed_work(). Note that the work callback | |
071b6386 ON |
152 | * function may still be running on return from cancel_delayed_work(), unless |
153 | * it returns 1 and the work doesn't re-arm itself. Run flush_workqueue() or | |
b89deed3 | 154 | * flush_work() or cancel_work_sync() to wait on it. |
1da177e4 | 155 | */ |
52bad64d | 156 | static inline int cancel_delayed_work(struct delayed_work *work) |
1da177e4 LT |
157 | { |
158 | int ret; | |
159 | ||
071b6386 | 160 | ret = del_timer(&work->timer); |
1da177e4 | 161 | if (ret) |
23b2e599 | 162 | work_clear_pending(&work->work); |
1da177e4 LT |
163 | return ret; |
164 | } | |
165 | ||
1634c48f ON |
166 | extern void cancel_rearming_delayed_work(struct delayed_work *work); |
167 | ||
168 | /* Obsolete. use cancel_rearming_delayed_work() */ | |
169 | static inline | |
170 | void cancel_rearming_delayed_workqueue(struct workqueue_struct *wq, | |
171 | struct delayed_work *work) | |
172 | { | |
173 | cancel_rearming_delayed_work(work); | |
174 | } | |
175 | ||
1da177e4 | 176 | #endif |