]> bbs.cooldavid.org Git - net-next-2.6.git/blame - include/linux/workqueue.h
unify flush_work/flush_work_keventd and rename it to cancel_work_sync
[net-next-2.6.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
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
35struct delayed_work {
36 struct work_struct work;
1da177e4
LT
37 struct timer_list timer;
38};
39
1fa44eca
JB
40struct 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 121extern 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
128extern void destroy_workqueue(struct workqueue_struct *wq);
129
130extern int FASTCALL(queue_work(struct workqueue_struct *wq, struct work_struct *work));
28e53bdd
ON
131extern int FASTCALL(queue_delayed_work(struct workqueue_struct *wq,
132 struct delayed_work *work, unsigned long delay));
7a6bc1cd 133extern int queue_delayed_work_on(int cpu, struct workqueue_struct *wq,
28e53bdd
ON
134 struct delayed_work *work, unsigned long delay);
135
1da177e4 136extern void FASTCALL(flush_workqueue(struct workqueue_struct *wq));
28e53bdd 137extern void flush_scheduled_work(void);
1da177e4
LT
138
139extern int FASTCALL(schedule_work(struct work_struct *work));
28e53bdd
ON
140extern int FASTCALL(schedule_delayed_work(struct delayed_work *work,
141 unsigned long delay));
142extern int schedule_delayed_work_on(int cpu, struct delayed_work *work,
143 unsigned long delay);
65f27f38 144extern int schedule_on_each_cpu(work_func_t func);
1da177e4
LT
145extern int current_is_keventd(void);
146extern int keventd_up(void);
147
148extern void init_workqueues(void);
65f27f38 149int execute_in_process_context(work_func_t fn, struct execute_work *);
1da177e4 150
28e53bdd
ON
151extern void cancel_work_sync(struct work_struct *work);
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 159static inline int cancel_delayed_work(struct delayed_work *work)
1da177e4
LT
160{
161 int ret;
162
071b6386 163 ret = del_timer(&work->timer);
1da177e4 164 if (ret)
23b2e599 165 work_clear_pending(&work->work);
1da177e4
LT
166 return ret;
167}
168
1634c48f
ON
169extern void cancel_rearming_delayed_work(struct delayed_work *work);
170
171/* Obsolete. use cancel_rearming_delayed_work() */
172static inline
173void cancel_rearming_delayed_workqueue(struct workqueue_struct *wq,
174 struct delayed_work *work)
175{
176 cancel_rearming_delayed_work(work);
177}
178
1da177e4 179#endif