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