]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - include/linux/workqueue.h
WorkStruct: Pass the work_struct pointer instead of context data
[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>
11
12struct workqueue_struct;
13
65f27f38
DH
14struct work_struct;
15typedef void (*work_func_t)(struct work_struct *work);
6bb49e59 16
1da177e4 17struct work_struct {
65f27f38
DH
18 /* the first word is the work queue pointer and the flags rolled into
19 * one */
365970a1
DH
20 unsigned long management;
21#define WORK_STRUCT_PENDING 0 /* T if work item pending execution */
65f27f38 22#define WORK_STRUCT_NOAUTOREL 1 /* F if work item automatically released on exec */
365970a1
DH
23#define WORK_STRUCT_FLAG_MASK (3UL)
24#define WORK_STRUCT_WQ_DATA_MASK (~WORK_STRUCT_FLAG_MASK)
1da177e4 25 struct list_head entry;
6bb49e59 26 work_func_t func;
52bad64d
DH
27};
28
29struct delayed_work {
30 struct work_struct work;
1da177e4
LT
31 struct timer_list timer;
32};
33
1fa44eca
JB
34struct execute_work {
35 struct work_struct work;
36};
37
65f27f38
DH
38#define __WORK_INITIALIZER(n, f) { \
39 .management = 0, \
1da177e4
LT
40 .entry = { &(n).entry, &(n).entry }, \
41 .func = (f), \
52bad64d
DH
42 }
43
65f27f38
DH
44#define __WORK_INITIALIZER_NAR(n, f) { \
45 .management = (1 << WORK_STRUCT_NOAUTOREL), \
46 .entry = { &(n).entry, &(n).entry }, \
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
55#define __DELAYED_WORK_INITIALIZER_NAR(n, f) { \
56 .work = __WORK_INITIALIZER_NAR((n).work, (f)), \
1da177e4
LT
57 .timer = TIMER_INITIALIZER(NULL, 0, 0), \
58 }
59
65f27f38
DH
60#define DECLARE_WORK(n, f) \
61 struct work_struct n = __WORK_INITIALIZER(n, f)
62
63#define DECLARE_WORK_NAR(n, f) \
64 struct work_struct n = __WORK_INITIALIZER_NAR(n, f)
1da177e4 65
65f27f38
DH
66#define DECLARE_DELAYED_WORK(n, f) \
67 struct delayed_work n = __DELAYED_WORK_INITIALIZER(n, f)
68
69#define DECLARE_DELAYED_WORK_NAR(n, f) \
70 struct dwork_struct n = __DELAYED_WORK_INITIALIZER_NAR(n, f)
52bad64d 71
1da177e4 72/*
65f27f38 73 * initialize a work item's function pointer
1da177e4 74 */
65f27f38 75#define PREPARE_WORK(_work, _func) \
1da177e4 76 do { \
52bad64d 77 (_work)->func = (_func); \
1da177e4
LT
78 } while (0)
79
65f27f38
DH
80#define PREPARE_DELAYED_WORK(_work, _func) \
81 PREPARE_WORK(&(_work)->work, (_func))
52bad64d 82
1da177e4 83/*
52bad64d 84 * initialize all of a work item in one go
1da177e4 85 */
65f27f38 86#define INIT_WORK(_work, _func) \
1da177e4 87 do { \
365970a1 88 (_work)->management = 0; \
65f27f38
DH
89 INIT_LIST_HEAD(&(_work)->entry); \
90 PREPARE_WORK((_work), (_func)); \
91 } while (0)
92
93#define INIT_WORK_NAR(_work, _func) \
94 do { \
95 (_work)->management = (1 << WORK_STRUCT_NOAUTOREL); \
96 INIT_LIST_HEAD(&(_work)->entry); \
97 PREPARE_WORK((_work), (_func)); \
98 } while (0)
99
100#define INIT_DELAYED_WORK(_work, _func) \
101 do { \
102 INIT_WORK(&(_work)->work, (_func)); \
103 init_timer(&(_work)->timer); \
52bad64d
DH
104 } while (0)
105
65f27f38 106#define INIT_DELAYED_WORK_NAR(_work, _func) \
52bad64d 107 do { \
65f27f38 108 INIT_WORK_NAR(&(_work)->work, (_func)); \
1da177e4
LT
109 init_timer(&(_work)->timer); \
110 } while (0)
111
365970a1
DH
112/**
113 * work_pending - Find out whether a work item is currently pending
114 * @work: The work item in question
115 */
116#define work_pending(work) \
117 test_bit(WORK_STRUCT_PENDING, &(work)->management)
118
119/**
120 * delayed_work_pending - Find out whether a delayable work item is currently
121 * pending
122 * @work: The work item in question
123 */
124#define delayed_work_pending(work) \
125 test_bit(WORK_STRUCT_PENDING, &(work)->work.management)
126
65f27f38
DH
127/**
128 * work_release - Release a work item under execution
129 * @work: The work item to release
130 *
131 * This is used to release a work item that has been initialised with automatic
132 * release mode disabled (WORK_STRUCT_NOAUTOREL is set). This gives the work
133 * function the opportunity to grab auxiliary data from the container of the
134 * work_struct before clearing the pending bit as the work_struct may be
135 * subject to deallocation the moment the pending bit is cleared.
136 *
137 * In such a case, this should be called in the work function after it has
138 * fetched any data it may require from the containter of the work_struct.
139 * After this function has been called, the work_struct may be scheduled for
140 * further execution or it may be deallocated unless other precautions are
141 * taken.
142 *
143 * This should also be used to release a delayed work item.
144 */
145#define work_release(work) \
146 clear_bit(WORK_STRUCT_PENDING, &(work)->management)
147
52bad64d 148
1da177e4
LT
149extern struct workqueue_struct *__create_workqueue(const char *name,
150 int singlethread);
151#define create_workqueue(name) __create_workqueue((name), 0)
152#define create_singlethread_workqueue(name) __create_workqueue((name), 1)
153
154extern void destroy_workqueue(struct workqueue_struct *wq);
155
156extern int FASTCALL(queue_work(struct workqueue_struct *wq, struct work_struct *work));
52bad64d 157extern int FASTCALL(queue_delayed_work(struct workqueue_struct *wq, struct delayed_work *work, unsigned long delay));
7a6bc1cd 158extern int queue_delayed_work_on(int cpu, struct workqueue_struct *wq,
52bad64d 159 struct delayed_work *work, unsigned long delay);
1da177e4
LT
160extern void FASTCALL(flush_workqueue(struct workqueue_struct *wq));
161
162extern int FASTCALL(schedule_work(struct work_struct *work));
52bad64d 163extern int FASTCALL(schedule_delayed_work(struct delayed_work *work, unsigned long delay));
1da177e4 164
52bad64d 165extern int schedule_delayed_work_on(int cpu, struct delayed_work *work, unsigned long delay);
65f27f38 166extern int schedule_on_each_cpu(work_func_t func);
1da177e4
LT
167extern void flush_scheduled_work(void);
168extern int current_is_keventd(void);
169extern int keventd_up(void);
170
171extern void init_workqueues(void);
52bad64d 172void cancel_rearming_delayed_work(struct delayed_work *work);
81ddef77 173void cancel_rearming_delayed_workqueue(struct workqueue_struct *,
52bad64d 174 struct delayed_work *);
65f27f38 175int execute_in_process_context(work_func_t fn, struct execute_work *);
1da177e4
LT
176
177/*
178 * Kill off a pending schedule_delayed_work(). Note that the work callback
179 * function may still be running on return from cancel_delayed_work(). Run
180 * flush_scheduled_work() to wait on it.
181 */
52bad64d 182static inline int cancel_delayed_work(struct delayed_work *work)
1da177e4
LT
183{
184 int ret;
185
186 ret = del_timer_sync(&work->timer);
187 if (ret)
365970a1 188 clear_bit(WORK_STRUCT_PENDING, &work->work.management);
1da177e4
LT
189 return ret;
190}
191
192#endif