Rev 2967 | Rev 3192 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2967 | Rev 3031 | ||
---|---|---|---|
1 | #ifndef _LINUX_WAIT_H |
1 | #ifndef _LINUX_WAIT_H |
2 | #define _LINUX_WAIT_H |
2 | #define _LINUX_WAIT_H |
3 | 3 | ||
4 | typedef struct __wait_queue wait_queue_t; |
4 | typedef struct __wait_queue wait_queue_t; |
5 | typedef struct __wait_queue_head wait_queue_head_t; |
5 | typedef struct __wait_queue_head wait_queue_head_t; |
6 | 6 | ||
7 | struct __wait_queue |
7 | struct __wait_queue |
8 | { |
8 | { |
9 | struct list_head task_list; |
9 | struct list_head task_list; |
10 | evhandle_t evnt; |
10 | evhandle_t evnt; |
11 | }; |
11 | }; |
12 | 12 | ||
13 | struct __wait_queue_head |
13 | struct __wait_queue_head |
14 | { |
14 | { |
15 | spinlock_t lock; |
15 | spinlock_t lock; |
16 | struct list_head task_list; |
16 | struct list_head task_list; |
17 | }; |
17 | }; |
18 | 18 | ||
19 | static inline void __add_wait_queue(wait_queue_head_t *head, wait_queue_t *new) |
19 | static inline void __add_wait_queue(wait_queue_head_t *head, wait_queue_t *new) |
20 | { |
20 | { |
21 | list_add(&new->task_list, &head->task_list); |
21 | list_add(&new->task_list, &head->task_list); |
22 | } |
22 | } |
23 | 23 | ||
24 | 24 | ||
25 | #define __wait_event(wq, condition) \ |
25 | #define __wait_event(wq, condition) \ |
26 | do { \ |
26 | do { \ |
27 | DEFINE_WAIT(__wait); \ |
27 | DEFINE_WAIT(__wait); \ |
28 | \ |
28 | \ |
29 | for (;;) { \ |
29 | for (;;) { \ |
30 | prepare_to_wait(&wq, &__wait, TASK_UNINTERRUPTIBLE); \ |
30 | prepare_to_wait(&wq, &__wait, TASK_UNINTERRUPTIBLE); \ |
31 | if (condition) \ |
31 | if (condition) \ |
32 | break; \ |
32 | break; \ |
33 | schedule(); \ |
33 | schedule(); \ |
34 | } \ |
34 | } \ |
35 | finish_wait(&wq, &__wait); \ |
35 | finish_wait(&wq, &__wait); \ |
36 | } while (0) |
36 | } while (0) |
37 | 37 | ||
- | 38 | ||
- | 39 | ||
- | 40 | ||
- | 41 | #define wait_event_timeout(wq, condition, timeout) \ |
|
- | 42 | ({ \ |
|
- | 43 | long __ret = timeout; \ |
|
- | 44 | do{ \ |
|
- | 45 | wait_queue_t __wait = { \ |
|
- | 46 | .task_list = LIST_HEAD_INIT(__wait.task_list), \ |
|
- | 47 | .evnt = CreateEvent(NULL, MANUAL_DESTROY), \ |
|
- | 48 | }; \ |
|
- | 49 | u32 flags; \ |
|
- | 50 | \ |
|
- | 51 | spin_lock_irqsave(&wq.lock, flags); \ |
|
- | 52 | if (list_empty(&__wait.task_list)) \ |
|
- | 53 | __add_wait_queue(&wq, &__wait); \ |
|
- | 54 | spin_unlock_irqrestore(&wq.lock, flags); \ |
|
- | 55 | \ |
|
- | 56 | for(;;){ \ |
|
- | 57 | if (condition) \ |
|
- | 58 | break; \ |
|
- | 59 | WaitEvent(__wait.evnt); \ |
|
- | 60 | }; \ |
|
- | 61 | if (!list_empty_careful(&__wait.task_list)) { \ |
|
- | 62 | spin_lock_irqsave(&wq.lock, flags); \ |
|
- | 63 | list_del_init(&__wait.task_list); \ |
|
- | 64 | spin_unlock_irqrestore(&wq.lock, flags); \ |
|
- | 65 | }; \ |
|
- | 66 | DestroyEvent(__wait.evnt); \ |
|
- | 67 | } while (0); \ |
|
- | 68 | __ret; \ |
|
- | 69 | }) |
|
- | 70 | ||
- | 71 | ||
38 | 72 | ||
39 | #define wait_event(wq, condition) \ |
73 | #define wait_event(wq, condition) \ |
40 | do{ \ |
74 | do{ \ |
41 | wait_queue_t __wait = { \ |
75 | wait_queue_t __wait = { \ |
42 | .task_list = LIST_HEAD_INIT(__wait.task_list), \ |
76 | .task_list = LIST_HEAD_INIT(__wait.task_list), \ |
43 | .evnt = CreateEvent(NULL, MANUAL_DESTROY), \ |
77 | .evnt = CreateEvent(NULL, MANUAL_DESTROY), \ |
44 | }; \ |
78 | }; \ |
45 | u32 flags; \ |
79 | u32 flags; \ |
46 | \ |
80 | \ |
47 | spin_lock_irqsave(&wq.lock, flags); \ |
81 | spin_lock_irqsave(&wq.lock, flags); \ |
48 | if (list_empty(&__wait.task_list)) \ |
82 | if (list_empty(&__wait.task_list)) \ |
49 | __add_wait_queue(&wq, &__wait); \ |
83 | __add_wait_queue(&wq, &__wait); \ |
50 | spin_unlock_irqrestore(&wq.lock, flags); \ |
84 | spin_unlock_irqrestore(&wq.lock, flags); \ |
51 | \ |
85 | \ |
52 | for(;;){ \ |
86 | for(;;){ \ |
53 | if (condition) \ |
87 | if (condition) \ |
54 | break; \ |
88 | break; \ |
55 | WaitEvent(__wait.evnt); \ |
89 | WaitEvent(__wait.evnt); \ |
56 | }; \ |
90 | }; \ |
57 | if (!list_empty_careful(&__wait.task_list)) { \ |
91 | if (!list_empty_careful(&__wait.task_list)) { \ |
58 | spin_lock_irqsave(&wq.lock, flags); \ |
92 | spin_lock_irqsave(&wq.lock, flags); \ |
59 | list_del_init(&__wait.task_list); \ |
93 | list_del_init(&__wait.task_list); \ |
60 | spin_unlock_irqrestore(&wq.lock, flags); \ |
94 | spin_unlock_irqrestore(&wq.lock, flags); \ |
61 | }; \ |
95 | }; \ |
62 | DestroyEvent(__wait.evnt); \ |
96 | DestroyEvent(__wait.evnt); \ |
63 | } while (0) |
97 | } while (0) |
64 | 98 | ||
- | 99 | ||
- | 100 | ||
65 | 101 | ||
66 | static inline |
102 | static inline |
67 | void wake_up_all(wait_queue_head_t *q) |
103 | void wake_up_all(wait_queue_head_t *q) |
68 | { |
104 | { |
69 | wait_queue_t *curr; |
105 | wait_queue_t *curr; |
70 | unsigned long flags; |
106 | unsigned long flags; |
71 | 107 | ||
72 | spin_lock_irqsave(&q->lock, flags); |
108 | spin_lock_irqsave(&q->lock, flags); |
73 | list_for_each_entry(curr, &q->task_list, task_list) |
109 | list_for_each_entry(curr, &q->task_list, task_list) |
74 | { |
110 | { |
75 | kevent_t event; |
111 | kevent_t event; |
76 | event.code = -1; |
112 | event.code = -1; |
77 | RaiseEvent(curr->evnt, 0, &event); |
113 | RaiseEvent(curr->evnt, 0, &event); |
78 | } |
114 | } |
79 | spin_unlock_irqrestore(&q->lock, flags); |
115 | spin_unlock_irqrestore(&q->lock, flags); |
80 | } |
116 | } |
81 | 117 | ||
82 | 118 | ||
83 | static inline void |
119 | static inline void |
84 | init_waitqueue_head(wait_queue_head_t *q) |
120 | init_waitqueue_head(wait_queue_head_t *q) |
85 | { |
121 | { |
86 | spin_lock_init(&q->lock); |
122 | spin_lock_init(&q->lock); |
87 | INIT_LIST_HEAD(&q->task_list); |
123 | INIT_LIST_HEAD(&q->task_list); |
88 | }; |
124 | }; |
89 | 125 | ||
90 | 126 | ||
91 | /* |
127 | /* |
92 | * Workqueue flags and constants. For details, please refer to |
128 | * Workqueue flags and constants. For details, please refer to |
93 | * Documentation/workqueue.txt. |
129 | * Documentation/workqueue.txt. |
94 | */ |
130 | */ |
95 | enum { |
131 | enum { |
96 | WQ_NON_REENTRANT = 1 << 0, /* guarantee non-reentrance */ |
132 | WQ_NON_REENTRANT = 1 << 0, /* guarantee non-reentrance */ |
97 | WQ_UNBOUND = 1 << 1, /* not bound to any cpu */ |
133 | WQ_UNBOUND = 1 << 1, /* not bound to any cpu */ |
98 | WQ_FREEZABLE = 1 << 2, /* freeze during suspend */ |
134 | WQ_FREEZABLE = 1 << 2, /* freeze during suspend */ |
99 | WQ_MEM_RECLAIM = 1 << 3, /* may be used for memory reclaim */ |
135 | WQ_MEM_RECLAIM = 1 << 3, /* may be used for memory reclaim */ |
100 | WQ_HIGHPRI = 1 << 4, /* high priority */ |
136 | WQ_HIGHPRI = 1 << 4, /* high priority */ |
101 | WQ_CPU_INTENSIVE = 1 << 5, /* cpu instensive workqueue */ |
137 | WQ_CPU_INTENSIVE = 1 << 5, /* cpu instensive workqueue */ |
102 | 138 | ||
103 | WQ_DRAINING = 1 << 6, /* internal: workqueue is draining */ |
139 | WQ_DRAINING = 1 << 6, /* internal: workqueue is draining */ |
104 | WQ_RESCUER = 1 << 7, /* internal: workqueue has rescuer */ |
140 | WQ_RESCUER = 1 << 7, /* internal: workqueue has rescuer */ |
105 | 141 | ||
106 | WQ_MAX_ACTIVE = 512, /* I like 512, better ideas? */ |
142 | WQ_MAX_ACTIVE = 512, /* I like 512, better ideas? */ |
107 | WQ_MAX_UNBOUND_PER_CPU = 4, /* 4 * #cpus for unbound wq */ |
143 | WQ_MAX_UNBOUND_PER_CPU = 4, /* 4 * #cpus for unbound wq */ |
108 | WQ_DFL_ACTIVE = WQ_MAX_ACTIVE / 2, |
144 | WQ_DFL_ACTIVE = WQ_MAX_ACTIVE / 2, |
109 | }; |
145 | }; |
110 | 146 | ||
111 | struct work_struct; |
147 | struct work_struct; |
112 | 148 | ||
113 | struct workqueue_struct { |
149 | struct workqueue_struct { |
114 | spinlock_t lock; |
150 | spinlock_t lock; |
115 | struct list_head worklist; |
151 | struct list_head worklist; |
116 | }; |
152 | }; |
117 | 153 | ||
118 | typedef void (*work_func_t)(struct work_struct *work); |
154 | typedef void (*work_func_t)(struct work_struct *work); |
119 | 155 | ||
120 | struct work_struct { |
156 | struct work_struct { |
121 | struct list_head entry; |
157 | struct list_head entry; |
122 | struct workqueue_struct *data; |
158 | struct workqueue_struct *data; |
123 | work_func_t func; |
159 | work_func_t func; |
124 | }; |
160 | }; |
125 | 161 | ||
126 | struct delayed_work { |
162 | struct delayed_work { |
127 | struct work_struct work; |
163 | struct work_struct work; |
128 | }; |
164 | }; |
129 | - | ||
130 | 165 | ||
131 | struct workqueue_struct *alloc_workqueue_key(const char *fmt, |
166 | struct workqueue_struct *alloc_workqueue_key(const char *fmt, |
132 | unsigned int flags, int max_active); |
167 | unsigned int flags, int max_active); |
- | 168 | ||
- | 169 | ||
- | 170 | #define alloc_ordered_workqueue(fmt, flags, args...) \ |
|
- | 171 | alloc_workqueue(fmt, WQ_UNBOUND | (flags), 1, ##args) |
|
133 | 172 | ||
134 | int queue_delayed_work(struct workqueue_struct *wq, |
173 | int queue_delayed_work(struct workqueue_struct *wq, |
135 | struct delayed_work *dwork, unsigned long delay); |
174 | struct delayed_work *dwork, unsigned long delay); |
136 | 175 | ||
137 | #define INIT_DELAYED_WORK(_work, _func) \ |
176 | #define INIT_DELAYED_WORK(_work, _func) \ |
138 | do { \ |
177 | do { \ |
139 | INIT_LIST_HEAD(&(_work)->work.entry); \ |
178 | INIT_LIST_HEAD(&(_work)->work.entry); \ |
140 | (_work)->work.func = _func; \ |
179 | (_work)->work.func = _func; \ |
141 | } while (0) |
180 | } while (0) |
- | 181 | ||
- | 182 | ||
- | 183 | struct completion { |
|
- | 184 | unsigned int done; |
|
- | 185 | wait_queue_head_t wait; |
|
- | 186 | }; |
|
- | 187 | ||
142 | 188 | ||
143 | #endif><>><>><>><>><>><>><>><> |
189 | #endif><>><>><>><>><>><>><>><> |