Removed support for special power management features
[~emulex/for-vlad/old/compat.git] / include / linux / kthread.h
1 /*
2  * Simple work processor based on kthread.
3  *
4  * This provides easier way to make use of kthreads.  A kthread_work
5  * can be queued and flushed using queue/flush_kthread_work()
6  * respectively.  Queued kthread_works are processed by a kthread
7  * running kthread_worker_fn().
8  *
9  * A kthread_work can't be freed while it is executing.
10  */
11 #ifndef BACKPORT_LINUX_KTHREAD_H
12 #define BACKPORT_LINUX_KTHREAD_H
13
14 #include <linux/version.h>
15
16 #include_next <linux/kthread.h>
17
18 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,35))
19
20 struct kthread_work;
21 typedef void (*kthread_work_func_t)(struct kthread_work *work);
22
23 struct kthread_worker {
24         spinlock_t              lock;
25         struct list_head        work_list;
26         struct task_struct      *task;
27 };
28
29 struct kthread_work {
30         struct list_head        node;
31         kthread_work_func_t     func;
32         wait_queue_head_t       done;
33         atomic_t                flushing;
34         int                     queue_seq;
35         int                     done_seq;
36 };
37
38 #define KTHREAD_WORKER_INIT(worker)     {                               \
39         .lock = __SPIN_LOCK_UNLOCKED((worker).lock),                    \
40         .work_list = LIST_HEAD_INIT((worker).work_list),                \
41         }
42
43 #define KTHREAD_WORK_INIT(work, fn)     {                               \
44         .node = LIST_HEAD_INIT((work).node),                            \
45         .func = (fn),                                                   \
46         .done = __WAIT_QUEUE_HEAD_INITIALIZER((work).done),             \
47         .flushing = ATOMIC_INIT(0),                                     \
48         }
49
50 #define DEFINE_KTHREAD_WORKER(worker)                                   \
51         struct kthread_worker worker = KTHREAD_WORKER_INIT(worker)
52
53 #define DEFINE_KTHREAD_WORK(work, fn)                                   \
54         struct kthread_work work = KTHREAD_WORK_INIT(work, fn)
55
56 /*
57  * kthread_worker.lock and kthread_work.done need their own lockdep class
58  * keys if they are defined on stack with lockdep enabled.  Use the
59  * following macros when defining them on stack.
60  */
61 #ifdef CONFIG_LOCKDEP
62 # define KTHREAD_WORKER_INIT_ONSTACK(worker)                            \
63         ({ init_kthread_worker(&worker); worker; })
64 # define DEFINE_KTHREAD_WORKER_ONSTACK(worker)                          \
65         struct kthread_worker worker = KTHREAD_WORKER_INIT_ONSTACK(worker)
66 # define KTHREAD_WORK_INIT_ONSTACK(work, fn)                            \
67         ({ init_kthread_work((&work), fn); work; })
68 # define DEFINE_KTHREAD_WORK_ONSTACK(work, fn)                          \
69         struct kthread_work work = KTHREAD_WORK_INIT_ONSTACK(work, fn)
70 #else
71 # define DEFINE_KTHREAD_WORKER_ONSTACK(worker) DEFINE_KTHREAD_WORKER(worker)
72 # define DEFINE_KTHREAD_WORK_ONSTACK(work, fn) DEFINE_KTHREAD_WORK(work, fn)
73 #endif
74
75 extern void __init_kthread_worker(struct kthread_worker *worker,
76                         const char *name, struct lock_class_key *key);
77
78 #define init_kthread_worker(worker)                                     \
79         do {                                                            \
80                 static struct lock_class_key __key;                     \
81                 __init_kthread_worker((worker), "("#worker")->lock", &__key); \
82         } while (0)
83
84 #define init_kthread_work(work, fn)                                     \
85         do {                                                            \
86                 memset((work), 0, sizeof(struct kthread_work));         \
87                 INIT_LIST_HEAD(&(work)->node);                          \
88                 (work)->func = (fn);                                    \
89                 init_waitqueue_head(&(work)->done);                     \
90         } while (0)
91
92 int kthread_worker_fn(void *worker_ptr);
93
94 bool queue_kthread_work(struct kthread_worker *worker,
95                         struct kthread_work *work);
96 void flush_kthread_work(struct kthread_work *work);
97 void flush_kthread_worker(struct kthread_worker *worker);
98
99 #endif /* LINUX_VERSION_CODE < 2.6.35 */
100
101 #if (LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,38))
102 /*
103  * Kernels between 2.6.36 and 2.6.38 have the above functions but still lack the
104  * following.
105  */
106 #define kthread_create_on_node(threadfn, data, node, namefmt, arg...) \
107         kthread_create(threadfn, data, namefmt, ##arg)
108
109 #endif /* LINUX_VERSION_CODE < 2.6.38 */
110
111 #endif /* _LINUX_KTHREAD_H */
112