]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - include/linux/workqueue.h
ipvs: flush defense_work before module unload
[mirror_ubuntu-artful-kernel.git] / include / linux / workqueue.h
CommitLineData
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
13struct workqueue_struct;
14
65f27f38
DH
15struct work_struct;
16typedef 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 24struct work_struct {
a08727ba 25 atomic_long_t data;
365970a1 26#define WORK_STRUCT_PENDING 0 /* T if work item pending execution */
65f27f38 27#define WORK_STRUCT_NOAUTOREL 1 /* F if work item automatically released on exec */
365970a1
DH
28#define WORK_STRUCT_FLAG_MASK (3UL)
29#define WORK_STRUCT_WQ_DATA_MASK (~WORK_STRUCT_FLAG_MASK)
1da177e4 30 struct list_head entry;
6bb49e59 31 work_func_t func;
52bad64d
DH
32};
33
a08727ba
LT
34#define WORK_DATA_INIT(autorelease) \
35 ATOMIC_LONG_INIT((autorelease) << WORK_STRUCT_NOAUTOREL)
36
52bad64d
DH
37struct delayed_work {
38 struct work_struct work;
1da177e4
LT
39 struct timer_list timer;
40};
41
1fa44eca
JB
42struct execute_work {
43 struct work_struct work;
44};
45
65f27f38 46#define __WORK_INITIALIZER(n, f) { \
a08727ba 47 .data = WORK_DATA_INIT(0), \
1da177e4
LT
48 .entry = { &(n).entry, &(n).entry }, \
49 .func = (f), \
52bad64d
DH
50 }
51
65f27f38 52#define __WORK_INITIALIZER_NAR(n, f) { \
a08727ba 53 .data = WORK_DATA_INIT(1), \
65f27f38
DH
54 .entry = { &(n).entry, &(n).entry }, \
55 .func = (f), \
56 }
57
58#define __DELAYED_WORK_INITIALIZER(n, f) { \
59 .work = __WORK_INITIALIZER((n).work, (f)), \
60 .timer = TIMER_INITIALIZER(NULL, 0, 0), \
61 }
62
63#define __DELAYED_WORK_INITIALIZER_NAR(n, f) { \
64 .work = __WORK_INITIALIZER_NAR((n).work, (f)), \
1da177e4
LT
65 .timer = TIMER_INITIALIZER(NULL, 0, 0), \
66 }
67
65f27f38
DH
68#define DECLARE_WORK(n, f) \
69 struct work_struct n = __WORK_INITIALIZER(n, f)
70
71#define DECLARE_WORK_NAR(n, f) \
72 struct work_struct n = __WORK_INITIALIZER_NAR(n, f)
1da177e4 73
65f27f38
DH
74#define DECLARE_DELAYED_WORK(n, f) \
75 struct delayed_work n = __DELAYED_WORK_INITIALIZER(n, f)
76
77#define DECLARE_DELAYED_WORK_NAR(n, f) \
78 struct dwork_struct n = __DELAYED_WORK_INITIALIZER_NAR(n, f)
52bad64d 79
1da177e4 80/*
65f27f38 81 * initialize a work item's function pointer
1da177e4 82 */
65f27f38 83#define PREPARE_WORK(_work, _func) \
1da177e4 84 do { \
52bad64d 85 (_work)->func = (_func); \
1da177e4
LT
86 } while (0)
87
65f27f38
DH
88#define PREPARE_DELAYED_WORK(_work, _func) \
89 PREPARE_WORK(&(_work)->work, (_func))
52bad64d 90
1da177e4 91/*
52bad64d 92 * initialize all of a work item in one go
a08727ba
LT
93 *
94 * NOTE! No point in using "atomic_long_set()": useing a direct
95 * assignment of the work data initializer allows the compiler
96 * to generate better code.
1da177e4 97 */
65f27f38 98#define INIT_WORK(_work, _func) \
1da177e4 99 do { \
a08727ba 100 (_work)->data = (atomic_long_t) WORK_DATA_INIT(0); \
65f27f38
DH
101 INIT_LIST_HEAD(&(_work)->entry); \
102 PREPARE_WORK((_work), (_func)); \
103 } while (0)
104
105#define INIT_WORK_NAR(_work, _func) \
106 do { \
a08727ba 107 (_work)->data = (atomic_long_t) WORK_DATA_INIT(1); \
65f27f38
DH
108 INIT_LIST_HEAD(&(_work)->entry); \
109 PREPARE_WORK((_work), (_func)); \
110 } while (0)
111
112#define INIT_DELAYED_WORK(_work, _func) \
113 do { \
114 INIT_WORK(&(_work)->work, (_func)); \
115 init_timer(&(_work)->timer); \
52bad64d
DH
116 } while (0)
117
65f27f38 118#define INIT_DELAYED_WORK_NAR(_work, _func) \
52bad64d 119 do { \
65f27f38 120 INIT_WORK_NAR(&(_work)->work, (_func)); \
1da177e4
LT
121 init_timer(&(_work)->timer); \
122 } while (0)
123
28287033
VP
124#define INIT_DELAYED_WORK_DEFERRABLE(_work, _func) \
125 do { \
126 INIT_WORK(&(_work)->work, (_func)); \
127 init_timer_deferrable(&(_work)->timer); \
128 } while (0)
129
365970a1
DH
130/**
131 * work_pending - Find out whether a work item is currently pending
132 * @work: The work item in question
133 */
134#define work_pending(work) \
a08727ba 135 test_bit(WORK_STRUCT_PENDING, work_data_bits(work))
365970a1
DH
136
137/**
138 * delayed_work_pending - Find out whether a delayable work item is currently
139 * pending
140 * @work: The work item in question
141 */
0221872a
LT
142#define delayed_work_pending(w) \
143 work_pending(&(w)->work)
365970a1 144
65f27f38
DH
145/**
146 * work_release - Release a work item under execution
147 * @work: The work item to release
148 *
149 * This is used to release a work item that has been initialised with automatic
150 * release mode disabled (WORK_STRUCT_NOAUTOREL is set). This gives the work
151 * function the opportunity to grab auxiliary data from the container of the
152 * work_struct before clearing the pending bit as the work_struct may be
153 * subject to deallocation the moment the pending bit is cleared.
154 *
155 * In such a case, this should be called in the work function after it has
156 * fetched any data it may require from the containter of the work_struct.
157 * After this function has been called, the work_struct may be scheduled for
158 * further execution or it may be deallocated unless other precautions are
159 * taken.
160 *
161 * This should also be used to release a delayed work item.
162 */
163#define work_release(work) \
a08727ba 164 clear_bit(WORK_STRUCT_PENDING, work_data_bits(work))
65f27f38 165
52bad64d 166
1da177e4 167extern struct workqueue_struct *__create_workqueue(const char *name,
341a5958
RW
168 int singlethread,
169 int freezeable);
170#define create_workqueue(name) __create_workqueue((name), 0, 0)
171#define create_freezeable_workqueue(name) __create_workqueue((name), 0, 1)
172#define create_singlethread_workqueue(name) __create_workqueue((name), 1, 0)
1da177e4
LT
173
174extern void destroy_workqueue(struct workqueue_struct *wq);
175
176extern int FASTCALL(queue_work(struct workqueue_struct *wq, struct work_struct *work));
52bad64d 177extern int FASTCALL(queue_delayed_work(struct workqueue_struct *wq, struct delayed_work *work, unsigned long delay));
7a6bc1cd 178extern int queue_delayed_work_on(int cpu, struct workqueue_struct *wq,
52bad64d 179 struct delayed_work *work, unsigned long delay);
1da177e4 180extern void FASTCALL(flush_workqueue(struct workqueue_struct *wq));
b89deed3
ON
181extern void flush_work(struct workqueue_struct *wq, struct work_struct *work);
182extern void flush_work_keventd(struct work_struct *work);
1da177e4
LT
183
184extern int FASTCALL(schedule_work(struct work_struct *work));
52bad64d 185extern int FASTCALL(schedule_delayed_work(struct delayed_work *work, unsigned long delay));
1da177e4 186
52bad64d 187extern int schedule_delayed_work_on(int cpu, struct delayed_work *work, unsigned long delay);
65f27f38 188extern int schedule_on_each_cpu(work_func_t func);
1da177e4
LT
189extern void flush_scheduled_work(void);
190extern int current_is_keventd(void);
191extern int keventd_up(void);
192
193extern void init_workqueues(void);
65f27f38 194int execute_in_process_context(work_func_t fn, struct execute_work *);
1da177e4
LT
195
196/*
197 * Kill off a pending schedule_delayed_work(). Note that the work callback
071b6386
ON
198 * function may still be running on return from cancel_delayed_work(), unless
199 * it returns 1 and the work doesn't re-arm itself. Run flush_workqueue() or
b89deed3 200 * flush_work() or cancel_work_sync() to wait on it.
1da177e4 201 */
52bad64d 202static inline int cancel_delayed_work(struct delayed_work *work)
1da177e4
LT
203{
204 int ret;
205
071b6386 206 ret = del_timer(&work->timer);
1da177e4 207 if (ret)
a08727ba 208 work_release(&work->work);
1da177e4
LT
209 return ret;
210}
211
1634c48f
ON
212extern void cancel_rearming_delayed_work(struct delayed_work *work);
213
214/* Obsolete. use cancel_rearming_delayed_work() */
215static inline
216void cancel_rearming_delayed_workqueue(struct workqueue_struct *wq,
217 struct delayed_work *work)
218{
219 cancel_rearming_delayed_work(work);
220}
221
1da177e4 222#endif