Rev 2336 | Rev 2421 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 2336 | Rev 2416 | ||
|---|---|---|---|
| Line 53... | Line 53... | ||
| 53 | */ |
53 | */ |
| 54 | void timeout_init(void) |
54 | void timeout_init(void) |
| 55 | { |
55 | { |
| 56 | spinlock_initialize(&CPU->timeoutlock, "timeout_lock"); |
56 | spinlock_initialize(&CPU->timeoutlock, "timeout_lock"); |
| 57 | 57 | ||
| - | 58 | #if defined CONFIG_TIMEOUT_AVL_TREE |
|
| - | 59 | avltree_create(&CPU->timeout_active_tree); |
|
| 58 | #ifdef CONFIG_TIMEOUT_EXTAVL_TREE |
60 | #elif defined CONFIG_TIMEOUT_EXTAVL_TREE |
| 59 | extavltree_create(&CPU->timeout_active_tree); |
61 | extavltree_create(&CPU->timeout_active_tree); |
| - | 62 | #elif defined CONFIG_TIMEOUT_EXTAVL_TREE |
|
| - | 63 | extavlreltree_create(&CPU->timeout_active_tree); |
|
| 60 | #else |
64 | #else |
| 61 | list_initialize(&CPU->timeout_active_head); |
65 | list_initialize(&CPU->timeout_active_head); |
| 62 | #endif |
66 | #endif |
| 63 | } |
67 | } |
| 64 | 68 | ||
| Line 73... | Line 77... | ||
| 73 | void timeout_reinitialize(timeout_t *t) |
77 | void timeout_reinitialize(timeout_t *t) |
| 74 | { |
78 | { |
| 75 | t->cpu = NULL; |
79 | t->cpu = NULL; |
| 76 | t->handler = NULL; |
80 | t->handler = NULL; |
| 77 | t->arg = NULL; |
81 | t->arg = NULL; |
| 78 | 82 | ||
| - | 83 | #if defined CONFIG_TIMEOUT_AVL_TREE |
|
| - | 84 | avltree_node_initialize(&t->node); |
|
| 79 | #ifdef CONFIG_TIMEOUT_EXTAVL_TREE |
85 | #elif defined CONFIG_TIMEOUT_EXTAVL_TREE |
| 80 | extavltree_node_initialize(&t->node); |
86 | extavltree_node_initialize(&t->node); |
| - | 87 | #elif defined CONFIG_TIMEOUT_EXTAVLREL_TREE |
|
| - | 88 | extavlreltree_node_initialize(&t->node); |
|
| 81 | #else |
89 | #else |
| 82 | t->ticks = 0; |
90 | t->ticks = 0; |
| 83 | link_initialize(&t->link); |
91 | link_initialize(&t->link); |
| 84 | #endif |
92 | #endif |
| 85 | } |
93 | } |
| Line 96... | Line 104... | ||
| 96 | { |
104 | { |
| 97 | spinlock_initialize(&t->lock, "timeout_t_lock"); |
105 | spinlock_initialize(&t->lock, "timeout_t_lock"); |
| 98 | timeout_reinitialize(t); |
106 | timeout_reinitialize(t); |
| 99 | } |
107 | } |
| 100 | 108 | ||
| - | 109 | #if defined CONFIG_TIMEOUT_AVL_TREE || \ |
|
| - | 110 | defined CONFIG_TIMEOUT_EXTAVL_TREE || \ |
|
| 101 | #ifdef CONFIG_TIMEOUT_EXTAVL_TREE |
111 | defined CONFIG_TIMEOUT_EXTAVLREL_TREE |
| - | 112 | ||
| 102 | /** Register timeout |
113 | /** Register timeout |
| 103 | * |
114 | * |
| 104 | * Insert timeout handler f (with argument arg) |
115 | * Insert timeout handler f (with argument arg) |
| 105 | * to timeout list and make it execute in |
116 | * to timeout ExtAVL tree and make it execute in |
| 106 | * time microseconds (or slightly more). |
117 | * time microseconds (or slightly more). |
| 107 | * |
118 | * |
| 108 | * @param t Timeout structure. |
119 | * @param t Timeout structure. |
| 109 | * @param time Number of usec in the future to execute |
120 | * @param time Number of usec in the future to execute |
| 110 | * the handler. |
121 | * the handler. |
| Line 122... | Line 133... | ||
| 122 | 133 | ||
| 123 | if (t->cpu) |
134 | if (t->cpu) |
| 124 | panic("t->cpu != 0"); |
135 | panic("t->cpu != 0"); |
| 125 | 136 | ||
| 126 | t->cpu = CPU; |
137 | t->cpu = CPU; |
| 127 | - | ||
| 128 | //tiky nejsou, musim zmenit klice primo v uzlech |
- | |
| 129 | - | ||
| 130 | t->handler = f; |
138 | t->handler = f; |
| 131 | t->arg = arg; |
139 | t->arg = arg; |
| - | 140 | t->node.key = us2ticks(time); |
|
| 132 | 141 | ||
| - | 142 | /* |
|
| - | 143 | * Put timeout into tree structure. |
|
| - | 144 | */ |
|
| - | 145 | #if defined CONFIG_TIMEOUT_AVL_TREE |
|
| - | 146 | avltree_insert(&CPU->timeout_active_tree,&t->node); |
|
| - | 147 | #elif defined CONFIG_TIMEOUT_EXTAVL_TREE |
|
| 133 | extavltree_insert(&CPU->timeout_active_tree,&t->node); |
148 | extavltree_insert(&CPU->timeout_active_tree,&t->node); |
| - | 149 | #elif defined CONFIG_TIMEOUT_EXTAVLREL_TREE |
|
| - | 150 | extavlreltree_insert(&CPU->timeout_active_tree,&t->node); |
|
| - | 151 | #endif |
|
| 134 | 152 | ||
| 135 | spinlock_unlock(&t->lock); |
153 | spinlock_unlock(&t->lock); |
| 136 | spinlock_unlock(&CPU->timeoutlock); |
154 | spinlock_unlock(&CPU->timeoutlock); |
| 137 | interrupts_restore(ipl); |
155 | interrupts_restore(ipl); |
| 138 | } |
156 | } |
| 139 | 157 | ||
| 140 | 158 | ||
| 141 | /** Unregister timeout |
159 | /** Unregister timeout |
| 142 | * |
160 | * |
| 143 | * Remove timeout from timeout list. |
161 | * Remove timeout from timeout ExtAVL tree structure. |
| 144 | * |
162 | * |
| 145 | * @param t Timeout to unregister. |
163 | * @param t Timeout to unregister. |
| 146 | * |
164 | * |
| 147 | * @return true on success, false on failure. |
165 | * @return true on success, false on failure. |
| 148 | */ |
166 | */ |
| Line 161... | Line 179... | ||
| 161 | if (!spinlock_trylock(&t->cpu->timeoutlock)) { |
179 | if (!spinlock_trylock(&t->cpu->timeoutlock)) { |
| 162 | spinlock_unlock(&t->lock); |
180 | spinlock_unlock(&t->lock); |
| 163 | interrupts_restore(ipl); |
181 | interrupts_restore(ipl); |
| 164 | goto grab_locks; |
182 | goto grab_locks; |
| 165 | } |
183 | } |
| 166 | - | ||
| 167 | /* |
184 | /* |
| 168 | * Now we know for sure that t hasn't been activated yet |
185 | * Now we know for sure that t hasn't been activated yet |
| 169 | * and is lurking in t->cpu->timeout_active_head queue. |
186 | * and is lurking in t->cpu->timeout_active_head queue. |
| 170 | */ |
187 | */ |
| 171 | 188 | ||
| - | 189 | /* |
|
| - | 190 | * Delete timeout from tree structure. |
|
| - | 191 | */ |
|
| - | 192 | #if defined CONFIG_TIMEOUT_AVL_TREE |
|
| - | 193 | avltree_delete(&CPU->timeout_active_tree,&t->node); |
|
| - | 194 | #elif defined CONFIG_TIMEOUT_EXTAVL_TREE |
|
| 172 | extavltree_delete(&CPU->timeout_active_tree,&t->node); |
195 | extavltree_delete(&CPU->timeout_active_tree,&t->node); |
| - | 196 | #elif defined CONFIG_TIMEOUT_EXTAVLREL_TREE |
|
| - | 197 | extavlreltree_delete(&CPU->timeout_active_tree,&t->node); |
|
| - | 198 | #endif |
|
| 173 | 199 | ||
| 174 | spinlock_unlock(&t->cpu->timeoutlock); |
200 | spinlock_unlock(&t->cpu->timeoutlock); |
| 175 | 201 | ||
| 176 | timeout_reinitialize(t); |
202 | timeout_reinitialize(t); |
| 177 | spinlock_unlock(&t->lock); |
203 | spinlock_unlock(&t->lock); |
| 178 | 204 | ||