Rev 404 | Rev 413 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 404 | Rev 411 | ||
---|---|---|---|
Line 50... | Line 50... | ||
50 | spinlock_initialize(&CPU->timeoutlock); |
50 | spinlock_initialize(&CPU->timeoutlock); |
51 | list_initialize(&CPU->timeout_active_head); |
51 | list_initialize(&CPU->timeout_active_head); |
52 | } |
52 | } |
53 | 53 | ||
54 | 54 | ||
55 | /** Initialize empty timeout list |
55 | /** Reinitialize timeout |
56 | * |
56 | * |
57 | * Initialize the timeout list to be empty. |
57 | * Initialize all members except the lock. |
58 | * |
58 | * |
59 | * @param t Timeout list to be initialized. |
59 | * @param t Timeout to be initialized. |
60 | * |
60 | * |
61 | */ |
61 | */ |
62 | void timeout_reinitialize(timeout_t *t) |
62 | void timeout_reinitialize(timeout_t *t) |
63 | { |
63 | { |
64 | t->cpu = NULL; |
64 | t->cpu = NULL; |
Line 67... | Line 67... | ||
67 | t->arg = NULL; |
67 | t->arg = NULL; |
68 | link_initialize(&t->link); |
68 | link_initialize(&t->link); |
69 | } |
69 | } |
70 | 70 | ||
71 | 71 | ||
72 | /** Initialize timeout list |
72 | /** Initialize timeout |
73 | * |
73 | * |
74 | * Initialize the timeout list and its spinlock. |
74 | * Initialize all members including the lock. |
75 | * |
75 | * |
76 | * @param t Timeout list to be initialized. |
76 | * @param t Timeout to be initialized. |
77 | * |
77 | * |
78 | */ |
78 | */ |
79 | void timeout_initialize(timeout_t *t) |
79 | void timeout_initialize(timeout_t *t) |
80 | { |
80 | { |
81 | spinlock_initialize(&t->lock); |
81 | spinlock_initialize(&t->lock); |
82 | timeout_reinitialize(t); |
82 | timeout_reinitialize(t); |
83 | } |
83 | } |
84 | 84 | ||
85 | 85 | ||
86 | /** Register timeout callback |
86 | /** Register timeout |
87 | * |
87 | * |
88 | * Insert the timeout handler f (with argument arg) |
88 | * Insert timeout handler f (with argument arg) |
89 | * to the timeout list and make it execute in |
89 | * to timeout list and make it execute in |
90 | * time microseconds (or slightly more). |
90 | * time microseconds (or slightly more). |
91 | * |
91 | * |
92 | * @param t Timeout list. |
92 | * @param t Timeout structure. |
93 | * @param time Number of usec in the future to execute |
93 | * @param time Number of usec in the future to execute |
94 | * the handler. |
94 | * the handler. |
95 | * @param f Timeout handler function. |
95 | * @param f Timeout handler function. |
96 | * @param arg Timeout handler argument. |
96 | * @param arg Timeout handler argument. |
97 | * |
97 | * |
98 | */ |
98 | */ |
99 | void timeout_register(timeout_t *t, __u64 time, timeout_handler f, void *arg) |
99 | void timeout_register(timeout_t *t, __u64 time, timeout_handler_t f, void *arg) |
100 | { |
100 | { |
101 | timeout_t *hlp; |
101 | timeout_t *hlp; |
102 | link_t *l, *m; |
102 | link_t *l, *m; |
103 | pri_t pri; |
103 | pri_t pri; |
104 | __u64 sum; |
104 | __u64 sum; |
Line 154... | Line 154... | ||
154 | spinlock_unlock(&CPU->timeoutlock); |
154 | spinlock_unlock(&CPU->timeoutlock); |
155 | cpu_priority_restore(pri); |
155 | cpu_priority_restore(pri); |
156 | } |
156 | } |
157 | 157 | ||
158 | 158 | ||
159 | /** Unregister timeout callback |
159 | /** Unregister timeout |
160 | * |
160 | * |
161 | * Remove timeout from timeout list. |
161 | * Remove timeout from timeout list. |
162 | * |
162 | * |
163 | * @param t Timeout to unregister. |
163 | * @param t Timeout to unregister. |
164 | * |
164 | * |
- | 165 | * @return true on success, false on failure. |
|
165 | */ |
166 | */ |
166 | int timeout_unregister(timeout_t *t) |
167 | bool timeout_unregister(timeout_t *t) |
167 | { |
168 | { |
168 | timeout_t *hlp; |
169 | timeout_t *hlp; |
169 | link_t *l; |
170 | link_t *l; |
170 | pri_t pri; |
171 | pri_t pri; |
171 | 172 | ||
Line 173... | Line 174... | ||
173 | pri = cpu_priority_high(); |
174 | pri = cpu_priority_high(); |
174 | spinlock_lock(&t->lock); |
175 | spinlock_lock(&t->lock); |
175 | if (!t->cpu) { |
176 | if (!t->cpu) { |
176 | spinlock_unlock(&t->lock); |
177 | spinlock_unlock(&t->lock); |
177 | cpu_priority_restore(pri); |
178 | cpu_priority_restore(pri); |
178 | return 0; |
179 | return false; |
179 | } |
180 | } |
180 | if (!spinlock_trylock(&t->cpu->timeoutlock)) { |
181 | if (!spinlock_trylock(&t->cpu->timeoutlock)) { |
181 | spinlock_unlock(&t->lock); |
182 | spinlock_unlock(&t->lock); |
182 | cpu_priority_restore(pri); |
183 | cpu_priority_restore(pri); |
183 | goto grab_locks; |
184 | goto grab_locks; |
Line 201... | Line 202... | ||
201 | 202 | ||
202 | timeout_reinitialize(t); |
203 | timeout_reinitialize(t); |
203 | spinlock_unlock(&t->lock); |
204 | spinlock_unlock(&t->lock); |
204 | 205 | ||
205 | cpu_priority_restore(pri); |
206 | cpu_priority_restore(pri); |
206 | return 1; |
207 | return true; |
207 | } |
208 | } |