7d9bf8a69e0e3fd6eeb1079de8e64d31e831650f
[~tnikolova/compat/.git] / compat / compat-2.6.36.c
1 /*
2  * Copyright 2010    Hauke Mehrtens <hauke@hauke-m.de>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation.
7  *
8  * Compatibility file for Linux wireless for kernels 2.6.36.
9  */
10
11 #include <linux/compat.h>
12
13 struct workqueue_struct *system_wq __read_mostly;
14 struct workqueue_struct *system_long_wq __read_mostly;
15 struct workqueue_struct *system_nrt_wq __read_mostly;
16 EXPORT_SYMBOL_GPL(system_wq);
17 EXPORT_SYMBOL_GPL(system_long_wq);
18 EXPORT_SYMBOL_GPL(system_nrt_wq);
19
20 int schedule_work(struct work_struct *work)
21 {
22         return queue_work(system_wq, work);
23 }
24 EXPORT_SYMBOL_GPL(schedule_work);
25
26 int schedule_work_on(int cpu, struct work_struct *work)
27 {
28 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27))
29         return queue_work_on(cpu, system_wq, work);
30 #else
31         return queue_work(system_wq, work);
32 #endif
33 }
34 EXPORT_SYMBOL_GPL(schedule_work_on);
35
36 int schedule_delayed_work(struct delayed_work *dwork,
37                                  unsigned long delay)
38 {
39         return queue_delayed_work(system_wq, dwork, delay);
40 }
41 EXPORT_SYMBOL_GPL(schedule_delayed_work);
42
43 int schedule_delayed_work_on(int cpu,
44                                     struct delayed_work *dwork,
45                                     unsigned long delay)
46 {
47         return queue_delayed_work_on(cpu, system_wq, dwork, delay);
48 }
49 EXPORT_SYMBOL_GPL(schedule_delayed_work_on);
50
51 void flush_scheduled_work(void)
52 {
53         /*
54          * It is debatable which one we should prioritize first, lets
55          * go with the old kernel's one first for now (keventd_wq) and
56          * if think its reasonable later we can flip this around.
57          */
58         flush_workqueue(system_wq);
59         flush_scheduled_work();
60 }
61 EXPORT_SYMBOL_GPL(flush_scheduled_work);
62
63 /**
64  * work_busy - test whether a work is currently pending or running
65  * @work: the work to be tested
66  *
67  * Test whether @work is currently pending or running.  There is no
68  * synchronization around this function and the test result is
69  * unreliable and only useful as advisory hints or for debugging.
70  * Especially for reentrant wqs, the pending state might hide the
71  * running state.
72  *
73  * RETURNS:
74  * OR'd bitmask of WORK_BUSY_* bits.
75  */
76 unsigned int work_busy(struct work_struct *work)
77 {
78         unsigned int ret = 0;
79
80         if (work_pending(work))
81                 ret |= WORK_BUSY_PENDING;
82
83         return ret;
84 }
85 EXPORT_SYMBOL_GPL(work_busy);
86
87 int backport_system_workqueue_create()
88 {
89         system_wq = alloc_workqueue("events", 0, 0);
90         if (!system_wq)
91                 return -ENOMEM;
92
93         system_long_wq = alloc_workqueue("events_long", 0, 0);
94         if (!system_long_wq)
95                 goto err1;
96
97         system_nrt_wq = create_singlethread_workqueue("events_nrt");
98         if (!system_nrt_wq)
99                 goto err2;
100
101         return 0;
102
103 err2:
104         destroy_workqueue(system_long_wq);
105 err1:
106         destroy_workqueue(system_wq);
107         return -ENOMEM;
108 }
109
110 void backport_system_workqueue_destroy()
111 {
112         destroy_workqueue(system_nrt_wq);
113         destroy_workqueue(system_wq);
114         destroy_workqueue(system_long_wq);
115 }