Rev 2450 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2450 | Rev 2461 | ||
---|---|---|---|
1 | /* |
1 | /* |
2 | * Copyright (C) 2001-2004 Jakub Jermar |
2 | * Copyright (C) 2001-2004 Jakub Jermar |
3 | * Copyright (C) 2007 Vojtech Mencl |
3 | * Copyright (C) 2007 Vojtech Mencl |
4 | * All rights reserved. |
4 | * All rights reserved. |
5 | * |
5 | * |
6 | * Redistribution and use in source and binary forms, with or without |
6 | * Redistribution and use in source and binary forms, with or without |
7 | * modification, are permitted provided that the following conditions |
7 | * modification, are permitted provided that the following conditions |
8 | * are met: |
8 | * are met: |
9 | * |
9 | * |
10 | * - Redistributions of source code must retain the above copyright |
10 | * - Redistributions of source code must retain the above copyright |
11 | * notice, this list of conditions and the following disclaimer. |
11 | * notice, this list of conditions and the following disclaimer. |
12 | * - Redistributions in binary form must reproduce the above copyright |
12 | * - Redistributions in binary form must reproduce the above copyright |
13 | * notice, this list of conditions and the following disclaimer in the |
13 | * notice, this list of conditions and the following disclaimer in the |
14 | * documentation and/or other materials provided with the distribution. |
14 | * documentation and/or other materials provided with the distribution. |
15 | * - The name of the author may not be used to endorse or promote products |
15 | * - The name of the author may not be used to endorse or promote products |
16 | * derived from this software without specific prior written permission. |
16 | * derived from this software without specific prior written permission. |
17 | * |
17 | * |
18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
19 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
19 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
20 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
20 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
21 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
21 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
22 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
22 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
23 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
23 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
24 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
25 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
27 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
28 | */ |
28 | */ |
29 | 29 | ||
30 | /** @addtogroup time |
30 | /** @addtogroup time |
31 | * @{ |
31 | * @{ |
32 | */ |
32 | */ |
33 | 33 | ||
34 | /** |
34 | /** |
35 | * @file |
35 | * @file |
36 | * @brief Timeout management functions. |
36 | * @brief Timeout management functions. |
37 | */ |
37 | */ |
38 | 38 | ||
39 | #include <time/timeout.h> |
39 | #include <time/timeout.h> |
40 | #include <arch/types.h> |
40 | #include <arch/types.h> |
41 | #include <config.h> |
41 | #include <config.h> |
42 | #include <panic.h> |
42 | #include <panic.h> |
43 | #include <synch/spinlock.h> |
43 | #include <synch/spinlock.h> |
44 | #include <func.h> |
44 | #include <func.h> |
45 | #include <cpu.h> |
45 | #include <cpu.h> |
46 | #include <arch/asm.h> |
46 | #include <arch/asm.h> |
47 | #include <arch.h> |
47 | #include <arch.h> |
48 | 48 | ||
49 | 49 | ||
50 | /** Initialize timeouts |
50 | /** Initialize timeouts |
51 | * |
51 | * |
52 | * Initialize kernel timeouts. |
52 | * Initialize kernel timeouts. |
53 | * |
53 | * |
54 | */ |
54 | */ |
55 | void timeout_init(void) |
55 | void timeout_init(void) |
56 | { |
56 | { |
57 | spinlock_initialize(&CPU->timeoutlock, "timeout_lock"); |
57 | spinlock_initialize(&CPU->timeoutlock, "timeout_lock"); |
58 | 58 | ||
59 | #if defined CONFIG_TIMEOUT_AVL_TREE |
59 | #if defined CONFIG_TIMEOUT_AVL_TREE |
60 | avltree_create(&CPU->timeout_active_tree); |
60 | avltree_create(&CPU->timeout_active_tree); |
- | 61 | #elif defined CONFIG_TIMEOUT_FAVL_TREE |
|
- | 62 | favltree_create(&CPU->timeout_active_tree); |
|
61 | #elif defined CONFIG_TIMEOUT_EXTAVL_TREE |
63 | #elif defined CONFIG_TIMEOUT_EXTAVL_TREE |
62 | extavltree_create(&CPU->timeout_active_tree); |
64 | extavltree_create(&CPU->timeout_active_tree); |
63 | #elif defined CONFIG_TIMEOUT_EXTAVLREL_TREE |
65 | #elif defined CONFIG_TIMEOUT_EXTAVLREL_TREE |
64 | extavlreltree_create(&CPU->timeout_active_tree); |
66 | extavlreltree_create(&CPU->timeout_active_tree); |
65 | #else |
67 | #else |
66 | list_initialize(&CPU->timeout_active_head); |
68 | list_initialize(&CPU->timeout_active_head); |
67 | #endif |
69 | #endif |
68 | } |
70 | } |
69 | 71 | ||
70 | 72 | ||
71 | /** Reinitialize timeout |
73 | /** Reinitialize timeout |
72 | * |
74 | * |
73 | * Initialize all members except the lock. |
75 | * Initialize all members except the lock. |
74 | * |
76 | * |
75 | * @param t Timeout to be initialized. |
77 | * @param t Timeout to be initialized. |
76 | * |
78 | * |
77 | */ |
79 | */ |
78 | void timeout_reinitialize(timeout_t *t) |
80 | void timeout_reinitialize(timeout_t *t) |
79 | { |
81 | { |
80 | t->cpu = NULL; |
82 | t->cpu = NULL; |
81 | t->handler = NULL; |
83 | t->handler = NULL; |
82 | t->arg = NULL; |
84 | t->arg = NULL; |
83 | 85 | ||
84 | #if defined CONFIG_TIMEOUT_AVL_TREE |
86 | #if defined CONFIG_TIMEOUT_AVL_TREE |
85 | avltree_node_initialize(&t->node); |
87 | avltree_node_initialize(&t->node); |
- | 88 | #elif defined CONFIG_TIMEOUT_FAVL_TREE |
|
- | 89 | favltree_node_initialize(&t->node); |
|
86 | #elif defined CONFIG_TIMEOUT_EXTAVL_TREE |
90 | #elif defined CONFIG_TIMEOUT_EXTAVL_TREE |
87 | extavltree_node_initialize(&t->node); |
91 | extavltree_node_initialize(&t->node); |
88 | #elif defined CONFIG_TIMEOUT_EXTAVLREL_TREE |
92 | #elif defined CONFIG_TIMEOUT_EXTAVLREL_TREE |
89 | extavlreltree_node_initialize(&t->node); |
93 | extavlreltree_node_initialize(&t->node); |
90 | #else |
94 | #else |
91 | t->ticks = 0; |
95 | t->ticks = 0; |
92 | link_initialize(&t->link); |
96 | link_initialize(&t->link); |
93 | #endif |
97 | #endif |
94 | } |
98 | } |
95 | 99 | ||
96 | 100 | ||
97 | /** Initialize timeout |
101 | /** Initialize timeout |
98 | * |
102 | * |
99 | * Initialize all members including the lock. |
103 | * Initialize all members including the lock. |
100 | * |
104 | * |
101 | * @param t Timeout to be initialized. |
105 | * @param t Timeout to be initialized. |
102 | * |
106 | * |
103 | */ |
107 | */ |
104 | void timeout_initialize(timeout_t *t) |
108 | void timeout_initialize(timeout_t *t) |
105 | { |
109 | { |
106 | spinlock_initialize(&t->lock, "timeout_t_lock"); |
110 | spinlock_initialize(&t->lock, "timeout_t_lock"); |
107 | timeout_reinitialize(t); |
111 | timeout_reinitialize(t); |
108 | } |
112 | } |
109 | 113 | ||
110 | #if defined CONFIG_TIMEOUT_AVL_TREE || \ |
114 | #if defined CONFIG_TIMEOUT_AVL_TREE || \ |
- | 115 | defined CONFIG_TIMEOUT_FAVL_TREE || \ |
|
111 | defined CONFIG_TIMEOUT_EXTAVL_TREE || \ |
116 | defined CONFIG_TIMEOUT_EXTAVL_TREE || \ |
112 | defined CONFIG_TIMEOUT_EXTAVLREL_TREE |
117 | defined CONFIG_TIMEOUT_EXTAVLREL_TREE |
113 | 118 | ||
114 | /** Register timeout |
119 | /** Register timeout |
115 | * |
120 | * |
116 | * Insert timeout handler f (with argument arg) |
121 | * Insert timeout handler f (with argument arg) |
117 | * to timeout ExtAVL tree and make it execute in |
122 | * to timeout tree and make it execute in |
118 | * time microseconds (or slightly more). |
123 | * time microseconds (or slightly more). |
119 | * |
124 | * |
120 | * @param t Timeout structure. |
125 | * @param t Timeout structure. |
121 | * @param time Number of usec in the future to execute |
126 | * @param time Number of usec in the future to execute |
122 | * the handler. |
127 | * the handler. |
123 | * @param f Timeout handler function. |
128 | * @param f Timeout handler function. |
124 | * @param arg Timeout handler argument. |
129 | * @param arg Timeout handler argument. |
125 | * |
130 | * |
126 | */ |
131 | */ |
127 | void timeout_register(timeout_t *t, uint64_t time, timeout_handler_t f, void *arg) |
132 | void timeout_register(timeout_t *t, uint64_t time, timeout_handler_t f, void *arg) |
128 | { |
133 | { |
129 | ipl_t ipl; |
134 | ipl_t ipl; |
130 | 135 | ||
131 | ipl = interrupts_disable(); |
136 | ipl = interrupts_disable(); |
132 | spinlock_lock(&CPU->timeoutlock); |
137 | spinlock_lock(&CPU->timeoutlock); |
133 | spinlock_lock(&t->lock); |
138 | spinlock_lock(&t->lock); |
134 | 139 | ||
135 | if (t->cpu) |
140 | if (t->cpu) |
136 | panic("t->cpu != 0"); |
141 | panic("t->cpu != 0"); |
137 | 142 | ||
138 | t->cpu = CPU; |
143 | t->cpu = CPU; |
139 | t->handler = f; |
144 | t->handler = f; |
140 | t->arg = arg; |
145 | t->arg = arg; |
141 | t->node.key = us2ticks(time); |
146 | t->node.key = us2ticks(time); |
142 | 147 | ||
143 | /* |
148 | /* |
144 | * Put timeout into tree structure. |
149 | * Insert timeout into tree structure. |
145 | */ |
150 | */ |
146 | #if defined CONFIG_TIMEOUT_AVL_TREE |
151 | #if defined CONFIG_TIMEOUT_AVL_TREE |
147 | avltree_insert(&CPU->timeout_active_tree,&t->node); |
152 | avltree_insert(&CPU->timeout_active_tree,&t->node); |
- | 153 | #elif defined CONFIG_TIMEOUT_FAVL_TREE |
|
- | 154 | favltree_insert(&CPU->timeout_active_tree,&t->node); |
|
148 | #elif defined CONFIG_TIMEOUT_EXTAVL_TREE |
155 | #elif defined CONFIG_TIMEOUT_EXTAVL_TREE |
149 | extavltree_insert(&CPU->timeout_active_tree,&t->node); |
156 | extavltree_insert(&CPU->timeout_active_tree,&t->node); |
150 | #elif defined CONFIG_TIMEOUT_EXTAVLREL_TREE |
157 | #elif defined CONFIG_TIMEOUT_EXTAVLREL_TREE |
151 | extavlreltree_insert(&CPU->timeout_active_tree,&t->node); |
158 | extavlreltree_insert(&CPU->timeout_active_tree,&t->node); |
152 | #endif |
159 | #endif |
153 | 160 | ||
154 | spinlock_unlock(&t->lock); |
161 | spinlock_unlock(&t->lock); |
155 | spinlock_unlock(&CPU->timeoutlock); |
162 | spinlock_unlock(&CPU->timeoutlock); |
156 | interrupts_restore(ipl); |
163 | interrupts_restore(ipl); |
157 | } |
164 | } |
158 | 165 | ||
159 | 166 | ||
160 | /** Unregister timeout |
167 | /** Unregister timeout |
161 | * |
168 | * |
162 | * Remove timeout from timeout ExtAVL tree structure. |
169 | * Remove timeout from timeout tree structure. |
163 | * |
170 | * |
164 | * @param t Timeout to unregister. |
171 | * @param t Timeout to unregister. |
165 | * |
172 | * |
166 | * @return true on success, false on failure. |
173 | * @return true on success, false on failure. |
167 | */ |
174 | */ |
168 | bool timeout_unregister(timeout_t *t) |
175 | bool timeout_unregister(timeout_t *t) |
169 | { |
176 | { |
170 | ipl_t ipl; |
177 | ipl_t ipl; |
171 | 178 | ||
172 | grab_locks: |
179 | grab_locks: |
173 | ipl = interrupts_disable(); |
180 | ipl = interrupts_disable(); |
174 | spinlock_lock(&t->lock); |
181 | spinlock_lock(&t->lock); |
175 | if (!t->cpu) { |
182 | if (!t->cpu) { |
176 | spinlock_unlock(&t->lock); |
183 | spinlock_unlock(&t->lock); |
177 | interrupts_restore(ipl); |
184 | interrupts_restore(ipl); |
178 | return false; |
185 | return false; |
179 | } |
186 | } |
180 | if (!spinlock_trylock(&t->cpu->timeoutlock)) { |
187 | if (!spinlock_trylock(&t->cpu->timeoutlock)) { |
181 | spinlock_unlock(&t->lock); |
188 | spinlock_unlock(&t->lock); |
182 | interrupts_restore(ipl); |
189 | interrupts_restore(ipl); |
183 | goto grab_locks; |
190 | goto grab_locks; |
184 | } |
191 | } |
185 | /* |
192 | /* |
186 | * Now we know for sure that t hasn't been activated yet |
193 | * Now we know for sure that t hasn't been activated yet |
187 | * and is lurking in t->cpu->timeout_active_head queue. |
194 | * and is lurking in t->cpu->timeout_active_head queue. |
188 | */ |
195 | */ |
189 | 196 | ||
190 | /* |
197 | /* |
191 | * Delete timeout from tree structure. |
198 | * Delete timeout from tree structure. |
192 | */ |
199 | */ |
193 | #if defined CONFIG_TIMEOUT_AVL_TREE |
200 | #if defined CONFIG_TIMEOUT_AVL_TREE |
194 | avltree_delete(&t->cpu->timeout_active_tree,&t->node); |
201 | avltree_delete(&t->cpu->timeout_active_tree,&t->node); |
- | 202 | #elif defined CONFIG_TIMEOUT_FAVL_TREE |
|
- | 203 | favltree_delete(&t->cpu->timeout_active_tree,&t->node); |
|
195 | #elif defined CONFIG_TIMEOUT_EXTAVL_TREE |
204 | #elif defined CONFIG_TIMEOUT_EXTAVL_TREE |
196 | extavltree_delete(&t->cpu->timeout_active_tree,&t->node); |
205 | extavltree_delete(&t->cpu->timeout_active_tree,&t->node); |
197 | #elif defined CONFIG_TIMEOUT_EXTAVLREL_TREE |
206 | #elif defined CONFIG_TIMEOUT_EXTAVLREL_TREE |
198 | extavlreltree_delete(&t->cpu->timeout_active_tree,&t->node); |
207 | extavlreltree_delete(&t->cpu->timeout_active_tree,&t->node); |
199 | #endif |
208 | #endif |
200 | 209 | ||
201 | spinlock_unlock(&t->cpu->timeoutlock); |
210 | spinlock_unlock(&t->cpu->timeoutlock); |
202 | 211 | ||
203 | timeout_reinitialize(t); |
212 | timeout_reinitialize(t); |
204 | spinlock_unlock(&t->lock); |
213 | spinlock_unlock(&t->lock); |
205 | 214 | ||
206 | interrupts_restore(ipl); |
215 | interrupts_restore(ipl); |
207 | return true; |
216 | return true; |
208 | } |
217 | } |
209 | 218 | ||
210 | #else |
219 | #else |
211 | 220 | ||
212 | /** Register timeout |
221 | /** Register timeout |
213 | * |
222 | * |
214 | * Insert timeout handler f (with argument arg) |
223 | * Insert timeout handler f (with argument arg) |
215 | * to timeout list and make it execute in |
224 | * to timeout list and make it execute in |
216 | * time microseconds (or slightly more). |
225 | * time microseconds (or slightly more). |
217 | * |
226 | * |
218 | * @param t Timeout structure. |
227 | * @param t Timeout structure. |
219 | * @param time Number of usec in the future to execute |
228 | * @param time Number of usec in the future to execute |
220 | * the handler. |
229 | * the handler. |
221 | * @param f Timeout handler function. |
230 | * @param f Timeout handler function. |
222 | * @param arg Timeout handler argument. |
231 | * @param arg Timeout handler argument. |
223 | * |
232 | * |
224 | */ |
233 | */ |
225 | void timeout_register(timeout_t *t, uint64_t time, timeout_handler_t f, void *arg) |
234 | void timeout_register(timeout_t *t, uint64_t time, timeout_handler_t f, void *arg) |
226 | { |
235 | { |
227 | timeout_t *hlp = NULL; |
236 | timeout_t *hlp = NULL; |
228 | link_t *l, *m; |
237 | link_t *l, *m; |
229 | ipl_t ipl; |
238 | ipl_t ipl; |
230 | uint64_t sum; |
239 | uint64_t sum; |
231 | 240 | ||
232 | ipl = interrupts_disable(); |
241 | ipl = interrupts_disable(); |
233 | spinlock_lock(&CPU->timeoutlock); |
242 | spinlock_lock(&CPU->timeoutlock); |
234 | spinlock_lock(&t->lock); |
243 | spinlock_lock(&t->lock); |
235 | 244 | ||
236 | if (t->cpu) |
245 | if (t->cpu) |
237 | panic("t->cpu != 0"); |
246 | panic("t->cpu != 0"); |
238 | 247 | ||
239 | t->cpu = CPU; |
248 | t->cpu = CPU; |
240 | t->ticks = us2ticks(time); |
249 | t->ticks = us2ticks(time); |
241 | 250 | ||
242 | t->handler = f; |
251 | t->handler = f; |
243 | t->arg = arg; |
252 | t->arg = arg; |
244 | 253 | ||
245 | /* |
254 | /* |
246 | * Insert t into the active timeouts list according to t->ticks. |
255 | * Insert t into the active timeouts list according to t->ticks. |
247 | */ |
256 | */ |
248 | sum = 0; |
257 | sum = 0; |
249 | l = CPU->timeout_active_head.next; |
258 | l = CPU->timeout_active_head.next; |
250 | while (l != &CPU->timeout_active_head) { |
259 | while (l != &CPU->timeout_active_head) { |
251 | hlp = list_get_instance(l, timeout_t, link); |
260 | hlp = list_get_instance(l, timeout_t, link); |
252 | spinlock_lock(&hlp->lock); |
261 | spinlock_lock(&hlp->lock); |
253 | if (t->ticks < sum + hlp->ticks) { |
262 | if (t->ticks < sum + hlp->ticks) { |
254 | spinlock_unlock(&hlp->lock); |
263 | spinlock_unlock(&hlp->lock); |
255 | break; |
264 | break; |
256 | } |
265 | } |
257 | sum += hlp->ticks; |
266 | sum += hlp->ticks; |
258 | spinlock_unlock(&hlp->lock); |
267 | spinlock_unlock(&hlp->lock); |
259 | l = l->next; |
268 | l = l->next; |
260 | } |
269 | } |
261 | 270 | ||
262 | m = l->prev; |
271 | m = l->prev; |
263 | list_prepend(&t->link, m); /* avoid using l->prev */ |
272 | list_prepend(&t->link, m); /* avoid using l->prev */ |
264 | 273 | ||
265 | /* |
274 | /* |
266 | * Adjust t->ticks according to ticks accumulated in h's predecessors. |
275 | * Adjust t->ticks according to ticks accumulated in h's predecessors. |
267 | */ |
276 | */ |
268 | t->ticks -= sum; |
277 | t->ticks -= sum; |
269 | 278 | ||
270 | /* |
279 | /* |
271 | * Decrease ticks of t's immediate succesor by t->ticks. |
280 | * Decrease ticks of t's immediate succesor by t->ticks. |
272 | */ |
281 | */ |
273 | if (l != &CPU->timeout_active_head) { |
282 | if (l != &CPU->timeout_active_head) { |
274 | spinlock_lock(&hlp->lock); |
283 | spinlock_lock(&hlp->lock); |
275 | hlp->ticks -= t->ticks; |
284 | hlp->ticks -= t->ticks; |
276 | spinlock_unlock(&hlp->lock); |
285 | spinlock_unlock(&hlp->lock); |
277 | } |
286 | } |
278 | 287 | ||
279 | spinlock_unlock(&t->lock); |
288 | spinlock_unlock(&t->lock); |
280 | spinlock_unlock(&CPU->timeoutlock); |
289 | spinlock_unlock(&CPU->timeoutlock); |
281 | interrupts_restore(ipl); |
290 | interrupts_restore(ipl); |
282 | } |
291 | } |
283 | 292 | ||
284 | 293 | ||
285 | /** Unregister timeout |
294 | /** Unregister timeout |
286 | * |
295 | * |
287 | * Remove timeout from timeout list. |
296 | * Remove timeout from timeout list. |
288 | * |
297 | * |
289 | * @param t Timeout to unregister. |
298 | * @param t Timeout to unregister. |
290 | * |
299 | * |
291 | * @return true on success, false on failure. |
300 | * @return true on success, false on failure. |
292 | */ |
301 | */ |
293 | bool timeout_unregister(timeout_t *t) |
302 | bool timeout_unregister(timeout_t *t) |
294 | { |
303 | { |
295 | timeout_t *hlp; |
304 | timeout_t *hlp; |
296 | link_t *l; |
305 | link_t *l; |
297 | ipl_t ipl; |
306 | ipl_t ipl; |
298 | 307 | ||
299 | grab_locks: |
308 | grab_locks: |
300 | ipl = interrupts_disable(); |
309 | ipl = interrupts_disable(); |
301 | spinlock_lock(&t->lock); |
310 | spinlock_lock(&t->lock); |
302 | if (!t->cpu) { |
311 | if (!t->cpu) { |
303 | spinlock_unlock(&t->lock); |
312 | spinlock_unlock(&t->lock); |
304 | interrupts_restore(ipl); |
313 | interrupts_restore(ipl); |
305 | return false; |
314 | return false; |
306 | } |
315 | } |
307 | if (!spinlock_trylock(&t->cpu->timeoutlock)) { |
316 | if (!spinlock_trylock(&t->cpu->timeoutlock)) { |
308 | spinlock_unlock(&t->lock); |
317 | spinlock_unlock(&t->lock); |
309 | interrupts_restore(ipl); |
318 | interrupts_restore(ipl); |
310 | goto grab_locks; |
319 | goto grab_locks; |
311 | } |
320 | } |
312 | 321 | ||
313 | /* |
322 | /* |
314 | * Now we know for sure that t hasn't been activated yet |
323 | * Now we know for sure that t hasn't been activated yet |
315 | * and is lurking in t->cpu->timeout_active_head queue. |
324 | * and is lurking in t->cpu->timeout_active_head queue. |
316 | */ |
325 | */ |
317 | 326 | ||
318 | l = t->link.next; |
327 | l = t->link.next; |
319 | if (l != &t->cpu->timeout_active_head) { |
328 | if (l != &t->cpu->timeout_active_head) { |
320 | hlp = list_get_instance(l, timeout_t, link); |
329 | hlp = list_get_instance(l, timeout_t, link); |
321 | spinlock_lock(&hlp->lock); |
330 | spinlock_lock(&hlp->lock); |
322 | hlp->ticks += t->ticks; |
331 | hlp->ticks += t->ticks; |
323 | spinlock_unlock(&hlp->lock); |
332 | spinlock_unlock(&hlp->lock); |
324 | } |
333 | } |
325 | 334 | ||
326 | list_remove(&t->link); |
335 | list_remove(&t->link); |
327 | spinlock_unlock(&t->cpu->timeoutlock); |
336 | spinlock_unlock(&t->cpu->timeoutlock); |
328 | 337 | ||
329 | timeout_reinitialize(t); |
338 | timeout_reinitialize(t); |
330 | spinlock_unlock(&t->lock); |
339 | spinlock_unlock(&t->lock); |
331 | 340 | ||
332 | interrupts_restore(ipl); |
341 | interrupts_restore(ipl); |
333 | return true; |
342 | return true; |
334 | } |
343 | } |
335 | 344 | ||
336 | #endif |
345 | #endif |
337 | /** @} |
346 | /** @} |
338 | */ |
347 | */ |
339 | 348 |