aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/workqueue.h
diff options
context:
space:
mode:
authorDavid Woodhouse <dwmw2@infradead.org>2007-01-17 18:34:51 -0500
committerDavid Woodhouse <dwmw2@infradead.org>2007-01-17 18:34:51 -0500
commit9cdf083f981b8d37b3212400a359368661385099 (patch)
treeaa15a6a08ad87e650dea40fb59b3180bef0d345b /include/linux/workqueue.h
parente499e01d234a31d59679b7b1e1cf628d917ba49a (diff)
parenta8b3485287731978899ced11f24628c927890e78 (diff)
Merge branch 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6
Diffstat (limited to 'include/linux/workqueue.h')
-rw-r--r--include/linux/workqueue.h166
1 files changed, 136 insertions, 30 deletions
diff --git a/include/linux/workqueue.h b/include/linux/workqueue.h
index 9bca3539a1e5..2a7b38d87018 100644
--- a/include/linux/workqueue.h
+++ b/include/linux/workqueue.h
@@ -8,15 +8,34 @@
8#include <linux/timer.h> 8#include <linux/timer.h>
9#include <linux/linkage.h> 9#include <linux/linkage.h>
10#include <linux/bitops.h> 10#include <linux/bitops.h>
11#include <asm/atomic.h>
11 12
12struct workqueue_struct; 13struct workqueue_struct;
13 14
15struct work_struct;
16typedef void (*work_func_t)(struct work_struct *work);
17
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
14struct work_struct { 24struct work_struct {
15 unsigned long pending; 25 atomic_long_t data;
26#define WORK_STRUCT_PENDING 0 /* T if work item pending execution */
27#define WORK_STRUCT_NOAUTOREL 1 /* F if work item automatically released on exec */
28#define WORK_STRUCT_FLAG_MASK (3UL)
29#define WORK_STRUCT_WQ_DATA_MASK (~WORK_STRUCT_FLAG_MASK)
16 struct list_head entry; 30 struct list_head entry;
17 void (*func)(void *); 31 work_func_t func;
18 void *data; 32};
19 void *wq_data; 33
34#define WORK_DATA_INIT(autorelease) \
35 ATOMIC_LONG_INIT((autorelease) << WORK_STRUCT_NOAUTOREL)
36
37struct delayed_work {
38 struct work_struct work;
20 struct timer_list timer; 39 struct timer_list timer;
21}; 40};
22 41
@@ -24,77 +43,164 @@ struct execute_work {
24 struct work_struct work; 43 struct work_struct work;
25}; 44};
26 45
27#define __WORK_INITIALIZER(n, f, d) { \ 46#define __WORK_INITIALIZER(n, f) { \
47 .data = WORK_DATA_INIT(0), \
48 .entry = { &(n).entry, &(n).entry }, \
49 .func = (f), \
50 }
51
52#define __WORK_INITIALIZER_NAR(n, f) { \
53 .data = WORK_DATA_INIT(1), \
28 .entry = { &(n).entry, &(n).entry }, \ 54 .entry = { &(n).entry, &(n).entry }, \
29 .func = (f), \ 55 .func = (f), \
30 .data = (d), \ 56 }
57
58#define __DELAYED_WORK_INITIALIZER(n, f) { \
59 .work = __WORK_INITIALIZER((n).work, (f)), \
31 .timer = TIMER_INITIALIZER(NULL, 0, 0), \ 60 .timer = TIMER_INITIALIZER(NULL, 0, 0), \
32 } 61 }
33 62
34#define DECLARE_WORK(n, f, d) \ 63#define __DELAYED_WORK_INITIALIZER_NAR(n, f) { \
35 struct work_struct n = __WORK_INITIALIZER(n, f, d) 64 .work = __WORK_INITIALIZER_NAR((n).work, (f)), \
65 .timer = TIMER_INITIALIZER(NULL, 0, 0), \
66 }
67
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)
73
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)
36 79
37/* 80/*
38 * initialize a work-struct's func and data pointers: 81 * initialize a work item's function pointer
39 */ 82 */
40#define PREPARE_WORK(_work, _func, _data) \ 83#define PREPARE_WORK(_work, _func) \
41 do { \ 84 do { \
42 (_work)->func = _func; \ 85 (_work)->func = (_func); \
43 (_work)->data = _data; \
44 } while (0) 86 } while (0)
45 87
88#define PREPARE_DELAYED_WORK(_work, _func) \
89 PREPARE_WORK(&(_work)->work, (_func))
90
46/* 91/*
47 * initialize all of a work-struct: 92 * initialize all of a work item in one go
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.
48 */ 97 */
49#define INIT_WORK(_work, _func, _data) \ 98#define INIT_WORK(_work, _func) \
50 do { \ 99 do { \
100 (_work)->data = (atomic_long_t) WORK_DATA_INIT(0); \
51 INIT_LIST_HEAD(&(_work)->entry); \ 101 INIT_LIST_HEAD(&(_work)->entry); \
52 (_work)->pending = 0; \ 102 PREPARE_WORK((_work), (_func)); \
53 PREPARE_WORK((_work), (_func), (_data)); \ 103 } while (0)
104
105#define INIT_WORK_NAR(_work, _func) \
106 do { \
107 (_work)->data = (atomic_long_t) WORK_DATA_INIT(1); \
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); \
116 } while (0)
117
118#define INIT_DELAYED_WORK_NAR(_work, _func) \
119 do { \
120 INIT_WORK_NAR(&(_work)->work, (_func)); \
54 init_timer(&(_work)->timer); \ 121 init_timer(&(_work)->timer); \
55 } while (0) 122 } while (0)
56 123
124/**
125 * work_pending - Find out whether a work item is currently pending
126 * @work: The work item in question
127 */
128#define work_pending(work) \
129 test_bit(WORK_STRUCT_PENDING, work_data_bits(work))
130
131/**
132 * delayed_work_pending - Find out whether a delayable work item is currently
133 * pending
134 * @work: The work item in question
135 */
136#define delayed_work_pending(w) \
137 work_pending(&(w)->work)
138
139/**
140 * work_release - Release a work item under execution
141 * @work: The work item to release
142 *
143 * This is used to release a work item that has been initialised with automatic
144 * release mode disabled (WORK_STRUCT_NOAUTOREL is set). This gives the work
145 * function the opportunity to grab auxiliary data from the container of the
146 * work_struct before clearing the pending bit as the work_struct may be
147 * subject to deallocation the moment the pending bit is cleared.
148 *
149 * In such a case, this should be called in the work function after it has
150 * fetched any data it may require from the containter of the work_struct.
151 * After this function has been called, the work_struct may be scheduled for
152 * further execution or it may be deallocated unless other precautions are
153 * taken.
154 *
155 * This should also be used to release a delayed work item.
156 */
157#define work_release(work) \
158 clear_bit(WORK_STRUCT_PENDING, work_data_bits(work))
159
160
57extern struct workqueue_struct *__create_workqueue(const char *name, 161extern struct workqueue_struct *__create_workqueue(const char *name,
58 int singlethread); 162 int singlethread,
59#define create_workqueue(name) __create_workqueue((name), 0) 163 int freezeable);
60#define create_singlethread_workqueue(name) __create_workqueue((name), 1) 164#define create_workqueue(name) __create_workqueue((name), 0, 0)
165#define create_freezeable_workqueue(name) __create_workqueue((name), 0, 1)
166#define create_singlethread_workqueue(name) __create_workqueue((name), 1, 0)
61 167
62extern void destroy_workqueue(struct workqueue_struct *wq); 168extern void destroy_workqueue(struct workqueue_struct *wq);
63 169
64extern int FASTCALL(queue_work(struct workqueue_struct *wq, struct work_struct *work)); 170extern int FASTCALL(queue_work(struct workqueue_struct *wq, struct work_struct *work));
65extern int FASTCALL(queue_delayed_work(struct workqueue_struct *wq, struct work_struct *work, unsigned long delay)); 171extern int FASTCALL(queue_delayed_work(struct workqueue_struct *wq, struct delayed_work *work, unsigned long delay));
66extern int queue_delayed_work_on(int cpu, struct workqueue_struct *wq, 172extern int queue_delayed_work_on(int cpu, struct workqueue_struct *wq,
67 struct work_struct *work, unsigned long delay); 173 struct delayed_work *work, unsigned long delay);
68extern void FASTCALL(flush_workqueue(struct workqueue_struct *wq)); 174extern void FASTCALL(flush_workqueue(struct workqueue_struct *wq));
69 175
70extern int FASTCALL(schedule_work(struct work_struct *work)); 176extern int FASTCALL(schedule_work(struct work_struct *work));
71extern int FASTCALL(schedule_delayed_work(struct work_struct *work, unsigned long delay)); 177extern int FASTCALL(run_scheduled_work(struct work_struct *work));
178extern int FASTCALL(schedule_delayed_work(struct delayed_work *work, unsigned long delay));
72 179
73extern int schedule_delayed_work_on(int cpu, struct work_struct *work, unsigned long delay); 180extern int schedule_delayed_work_on(int cpu, struct delayed_work *work, unsigned long delay);
74extern int schedule_on_each_cpu(void (*func)(void *info), void *info); 181extern int schedule_on_each_cpu(work_func_t func);
75extern void flush_scheduled_work(void); 182extern void flush_scheduled_work(void);
76extern int current_is_keventd(void); 183extern int current_is_keventd(void);
77extern int keventd_up(void); 184extern int keventd_up(void);
78 185
79extern void init_workqueues(void); 186extern void init_workqueues(void);
80void cancel_rearming_delayed_work(struct work_struct *work); 187void cancel_rearming_delayed_work(struct delayed_work *work);
81void cancel_rearming_delayed_workqueue(struct workqueue_struct *, 188void cancel_rearming_delayed_workqueue(struct workqueue_struct *,
82 struct work_struct *); 189 struct delayed_work *);
83int execute_in_process_context(void (*fn)(void *), void *, 190int execute_in_process_context(work_func_t fn, struct execute_work *);
84 struct execute_work *);
85 191
86/* 192/*
87 * Kill off a pending schedule_delayed_work(). Note that the work callback 193 * Kill off a pending schedule_delayed_work(). Note that the work callback
88 * function may still be running on return from cancel_delayed_work(). Run 194 * function may still be running on return from cancel_delayed_work(). Run
89 * flush_scheduled_work() to wait on it. 195 * flush_scheduled_work() to wait on it.
90 */ 196 */
91static inline int cancel_delayed_work(struct work_struct *work) 197static inline int cancel_delayed_work(struct delayed_work *work)
92{ 198{
93 int ret; 199 int ret;
94 200
95 ret = del_timer_sync(&work->timer); 201 ret = del_timer_sync(&work->timer);
96 if (ret) 202 if (ret)
97 clear_bit(0, &work->pending); 203 work_release(&work->work);
98 return ret; 204 return ret;
99} 205}
100 206