Rev 2909 | Rev 2916 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 2909 | Rev 2914 | ||
|---|---|---|---|
| Line 58... | Line 58... | ||
| 58 | 58 | ||
| 59 | /** Initialize wait queue |
59 | /** Initialize wait queue |
| 60 | * |
60 | * |
| 61 | * Initialize wait queue. |
61 | * Initialize wait queue. |
| 62 | * |
62 | * |
| 63 | * @param wq Pointer to wait queue to be initialized. |
63 | * @param wq Pointer to wait queue to be initialized. |
| 64 | */ |
64 | */ |
| 65 | void waitq_initialize(waitq_t *wq) |
65 | void waitq_initialize(waitq_t *wq) |
| 66 | { |
66 | { |
| 67 | spinlock_initialize(&wq->lock, "waitq_lock"); |
67 | spinlock_initialize(&wq->lock, "waitq_lock"); |
| 68 | list_initialize(&wq->head); |
68 | list_initialize(&wq->head); |
| 69 | wq->missed_wakeups = 0; |
69 | wq->missed_wakeups = 0; |
| 70 | } |
70 | } |
| 71 | 71 | ||
| 72 | /** Handle timeout during waitq_sleep_timeout() call |
72 | /** Handle timeout during waitq_sleep_timeout() call |
| 73 | * |
73 | * |
| 74 | * This routine is called when waitq_sleep_timeout() timeouts. |
74 | * This routine is called when waitq_sleep_timeout() times out. |
| 75 | * Interrupts are disabled. |
75 | * Interrupts are disabled. |
| 76 | * |
76 | * |
| 77 | * It is supposed to try to remove 'its' thread from the wait queue; |
77 | * It is supposed to try to remove 'its' thread from the wait queue; |
| 78 | * it can eventually fail to achieve this goal when these two events |
78 | * it can eventually fail to achieve this goal when these two events |
| 79 | * overlap. In that case it behaves just as though there was no |
79 | * overlap. In that case it behaves just as though there was no |
| 80 | * timeout at all. |
80 | * timeout at all. |
| 81 | * |
81 | * |
| 82 | * @param data Pointer to the thread that called waitq_sleep_timeout(). |
82 | * @param data Pointer to the thread that called waitq_sleep_timeout(). |
| 83 | */ |
83 | */ |
| 84 | void waitq_sleep_timed_out(void *data) |
84 | void waitq_sleep_timed_out(void *data) |
| 85 | { |
85 | { |
| 86 | thread_t *t = (thread_t *) data; |
86 | thread_t *t = (thread_t *) data; |
| 87 | waitq_t *wq; |
87 | waitq_t *wq; |
| Line 121... | Line 121... | ||
| 121 | /** Interrupt sleeping thread. |
121 | /** Interrupt sleeping thread. |
| 122 | * |
122 | * |
| 123 | * This routine attempts to interrupt a thread from its sleep in a waitqueue. |
123 | * This routine attempts to interrupt a thread from its sleep in a waitqueue. |
| 124 | * If the thread is not found sleeping, no action is taken. |
124 | * If the thread is not found sleeping, no action is taken. |
| 125 | * |
125 | * |
| 126 | * @param t Thread to be interrupted. |
126 | * @param t Thread to be interrupted. |
| 127 | */ |
127 | */ |
| 128 | void waitq_interrupt_sleep(thread_t *t) |
128 | void waitq_interrupt_sleep(thread_t *t) |
| 129 | { |
129 | { |
| 130 | waitq_t *wq; |
130 | waitq_t *wq; |
| 131 | bool do_wakeup = false; |
131 | bool do_wakeup = false; |
| Line 232... | Line 232... | ||
| 232 | /** Prepare to sleep in a waitq. |
232 | /** Prepare to sleep in a waitq. |
| 233 | * |
233 | * |
| 234 | * This function will return holding the lock of the wait queue |
234 | * This function will return holding the lock of the wait queue |
| 235 | * and interrupts disabled. |
235 | * and interrupts disabled. |
| 236 | * |
236 | * |
| 237 | * @param wq Wait queue. |
237 | * @param wq Wait queue. |
| 238 | * |
238 | * |
| 239 | * @return Interrupt level as it existed on entry to this function. |
239 | * @return Interrupt level as it existed on entry to this function. |
| 240 | */ |
240 | */ |
| 241 | ipl_t waitq_sleep_prepare(waitq_t *wq) |
241 | ipl_t waitq_sleep_prepare(waitq_t *wq) |
| 242 | { |
242 | { |
| 243 | ipl_t ipl; |
243 | ipl_t ipl; |
| 244 | 244 | ||
| Line 270... | Line 270... | ||
| 270 | * |
270 | * |
| 271 | * This function restores interrupts to the state that existed prior |
271 | * This function restores interrupts to the state that existed prior |
| 272 | * to the call to waitq_sleep_prepare(). If necessary, the wait queue |
272 | * to the call to waitq_sleep_prepare(). If necessary, the wait queue |
| 273 | * lock is released. |
273 | * lock is released. |
| 274 | * |
274 | * |
| 275 | * @param wq Wait queue. |
275 | * @param wq Wait queue. |
| 276 | * @param rc Return code of waitq_sleep_timeout_unsafe(). |
276 | * @param rc Return code of waitq_sleep_timeout_unsafe(). |
| 277 | * @param ipl Interrupt level returned by waitq_sleep_prepare(). |
277 | * @param ipl Interrupt level returned by waitq_sleep_prepare(). |
| 278 | */ |
278 | */ |
| 279 | void waitq_sleep_finish(waitq_t *wq, int rc, ipl_t ipl) |
279 | void waitq_sleep_finish(waitq_t *wq, int rc, ipl_t ipl) |
| 280 | { |
280 | { |
| 281 | switch (rc) { |
281 | switch (rc) { |
| 282 | case ESYNCH_WOULD_BLOCK: |
282 | case ESYNCH_WOULD_BLOCK: |
| Line 290... | Line 290... | ||
| 290 | } |
290 | } |
| 291 | 291 | ||
| 292 | /** Internal implementation of waitq_sleep_timeout(). |
292 | /** Internal implementation of waitq_sleep_timeout(). |
| 293 | * |
293 | * |
| 294 | * This function implements logic of sleeping in a wait queue. |
294 | * This function implements logic of sleeping in a wait queue. |
| 295 | * This call must be preceeded by a call to waitq_sleep_prepare() |
295 | * This call must be preceded by a call to waitq_sleep_prepare() |
| 296 | * and followed by a call to waitq_slee_finish(). |
296 | * and followed by a call to waitq_sleep_finish(). |
| 297 | * |
297 | * |
| 298 | * @param wq See waitq_sleep_timeout(). |
298 | * @param wq See waitq_sleep_timeout(). |
| 299 | * @param usec See waitq_sleep_timeout(). |
299 | * @param usec See waitq_sleep_timeout(). |
| 300 | * @param flags See waitq_sleep_timeout(). |
300 | * @param flags See waitq_sleep_timeout(). |
| 301 | * |
301 | * |
| 302 | * @return See waitq_sleep_timeout(). |
302 | * @return See waitq_sleep_timeout(). |
| 303 | */ |
303 | */ |
| 304 | int waitq_sleep_timeout_unsafe(waitq_t *wq, uint32_t usec, int flags) |
304 | int waitq_sleep_timeout_unsafe(waitq_t *wq, uint32_t usec, int flags) |
| 305 | { |
305 | { |
| 306 | /* checks whether to go to sleep at all */ |
306 | /* checks whether to go to sleep at all */ |
| 307 | if (wq->missed_wakeups) { |
307 | if (wq->missed_wakeups) { |
| Line 382... | Line 382... | ||
| 382 | * wrapper meant for general use. |
382 | * wrapper meant for general use. |
| 383 | * |
383 | * |
| 384 | * Besides its 'normal' wakeup operation, it attempts to unregister possible |
384 | * Besides its 'normal' wakeup operation, it attempts to unregister possible |
| 385 | * timeout. |
385 | * timeout. |
| 386 | * |
386 | * |
| 387 | * @param wq Pointer to wait queue. |
387 | * @param wq Pointer to wait queue. |
| 388 | * @param mode Wakeup mode. |
388 | * @param mode Wakeup mode. |
| 389 | */ |
389 | */ |
| 390 | void waitq_wakeup(waitq_t *wq, wakeup_mode_t mode) |
390 | void waitq_wakeup(waitq_t *wq, wakeup_mode_t mode) |
| 391 | { |
391 | { |
| 392 | ipl_t ipl; |
392 | ipl_t ipl; |
| 393 | 393 | ||
| Line 403... | Line 403... | ||
| 403 | /** Internal SMP- and IRQ-unsafe version of waitq_wakeup() |
403 | /** Internal SMP- and IRQ-unsafe version of waitq_wakeup() |
| 404 | * |
404 | * |
| 405 | * This is the internal SMP- and IRQ-unsafe version of waitq_wakeup(). It |
405 | * This is the internal SMP- and IRQ-unsafe version of waitq_wakeup(). It |
| 406 | * assumes wq->lock is already locked and interrupts are already disabled. |
406 | * assumes wq->lock is already locked and interrupts are already disabled. |
| 407 | * |
407 | * |
| 408 | * @param wq Pointer to wait queue. |
408 | * @param wq Pointer to wait queue. |
| 409 | * @param mode If mode is WAKEUP_FIRST, then the longest waiting thread, |
409 | * @param mode If mode is WAKEUP_FIRST, then the longest waitingi |
| 410 | * if any, is woken up. If mode is WAKEUP_ALL, then all |
410 | * thread, if any, is woken up. If mode is WAKEUP_ALL, then |
| 411 | * waiting threads, if any, are woken up. If there are no |
411 | * all waiting threads, if any, are woken up. If there are |
| 412 | * waiting threads to be woken up, the missed wakeup is |
412 | * no waiting threads to be woken up, the missed wakeup is |
| 413 | * recorded in the wait queue. |
413 | * recorded in the wait queue. |
| 414 | */ |
414 | */ |
| 415 | void _waitq_wakeup_unsafe(waitq_t *wq, wakeup_mode_t mode) |
415 | void _waitq_wakeup_unsafe(waitq_t *wq, wakeup_mode_t mode) |
| 416 | { |
416 | { |
| 417 | thread_t *t; |
417 | thread_t *t; |
| 418 | count_t count = 0; |
418 | count_t count = 0; |