WorkStruct: Typedef the work function prototype
[safe/jmp/linux-2.6] / include / linux / workqueue.h
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
12 struct workqueue_struct;
13
14 typedef void (*work_func_t)(void *data);
15
16 struct work_struct {
17         unsigned long pending;
18         struct list_head entry;
19         work_func_t func;
20         void *data;
21         void *wq_data;
22 };
23
24 struct delayed_work {
25         struct work_struct work;
26         struct timer_list timer;
27 };
28
29 struct execute_work {
30         struct work_struct work;
31 };
32
33 #define __WORK_INITIALIZER(n, f, d) {                           \
34         .entry  = { &(n).entry, &(n).entry },                   \
35         .func = (f),                                            \
36         .data = (d),                                            \
37         }
38
39 #define __DELAYED_WORK_INITIALIZER(n, f, d) {                   \
40         .work = __WORK_INITIALIZER((n).work, (f), (d)),         \
41         .timer = TIMER_INITIALIZER(NULL, 0, 0),                 \
42         }
43
44 #define DECLARE_WORK(n, f, d)                                   \
45         struct work_struct n = __WORK_INITIALIZER(n, f, d)
46
47 #define DECLARE_DELAYED_WORK(n, f, d)                           \
48         struct delayed_work n = __DELAYED_WORK_INITIALIZER(n, f, d)
49
50 /*
51  * initialize a work item's function and data pointers
52  */
53 #define PREPARE_WORK(_work, _func, _data)                       \
54         do {                                                    \
55                 (_work)->func = (_func);                        \
56                 (_work)->data = (_data);                        \
57         } while (0)
58
59 #define PREPARE_DELAYED_WORK(_work, _func, _data)               \
60         PREPARE_WORK(&(_work)->work, (_func), (_data))
61
62 /*
63  * initialize all of a work item in one go
64  */
65 #define INIT_WORK(_work, _func, _data)                          \
66         do {                                                    \
67                 INIT_LIST_HEAD(&(_work)->entry);                \
68                 (_work)->pending = 0;                           \
69                 PREPARE_WORK((_work), (_func), (_data));        \
70         } while (0)
71
72 #define INIT_DELAYED_WORK(_work, _func, _data)          \
73         do {                                                    \
74                 INIT_WORK(&(_work)->work, (_func), (_data));    \
75                 init_timer(&(_work)->timer);                    \
76         } while (0)
77
78
79 extern struct workqueue_struct *__create_workqueue(const char *name,
80                                                     int singlethread);
81 #define create_workqueue(name) __create_workqueue((name), 0)
82 #define create_singlethread_workqueue(name) __create_workqueue((name), 1)
83
84 extern void destroy_workqueue(struct workqueue_struct *wq);
85
86 extern int FASTCALL(queue_work(struct workqueue_struct *wq, struct work_struct *work));
87 extern int FASTCALL(queue_delayed_work(struct workqueue_struct *wq, struct delayed_work *work, unsigned long delay));
88 extern int queue_delayed_work_on(int cpu, struct workqueue_struct *wq,
89         struct delayed_work *work, unsigned long delay);
90 extern void FASTCALL(flush_workqueue(struct workqueue_struct *wq));
91
92 extern int FASTCALL(schedule_work(struct work_struct *work));
93 extern int FASTCALL(schedule_delayed_work(struct delayed_work *work, unsigned long delay));
94
95 extern int schedule_delayed_work_on(int cpu, struct delayed_work *work, unsigned long delay);
96 extern int schedule_on_each_cpu(work_func_t func, void *info);
97 extern void flush_scheduled_work(void);
98 extern int current_is_keventd(void);
99 extern int keventd_up(void);
100
101 extern void init_workqueues(void);
102 void cancel_rearming_delayed_work(struct delayed_work *work);
103 void cancel_rearming_delayed_workqueue(struct workqueue_struct *,
104                                        struct delayed_work *);
105 int execute_in_process_context(work_func_t fn, void *, struct execute_work *);
106
107 /*
108  * Kill off a pending schedule_delayed_work().  Note that the work callback
109  * function may still be running on return from cancel_delayed_work().  Run
110  * flush_scheduled_work() to wait on it.
111  */
112 static inline int cancel_delayed_work(struct delayed_work *work)
113 {
114         int ret;
115
116         ret = del_timer_sync(&work->timer);
117         if (ret)
118                 clear_bit(0, &work->work.pending);
119         return ret;
120 }
121
122 #endif