Rev 1787 | Rev 2071 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 1787 | Rev 2067 | ||
|---|---|---|---|
| Line 186... | Line 186... | ||
| 186 | * |
186 | * |
| 187 | * The sleep can be interrupted only if the |
187 | * The sleep can be interrupted only if the |
| 188 | * SYNCH_FLAGS_INTERRUPTIBLE bit is specified in flags. |
188 | * SYNCH_FLAGS_INTERRUPTIBLE bit is specified in flags. |
| 189 | |
189 | |
| 190 | * If usec is greater than zero, regardless of the value of the |
190 | * If usec is greater than zero, regardless of the value of the |
| 191 | * SYNCH_FLAGS_NON_BLOCKING bit in flags, the call will not return until either timeout, |
191 | * SYNCH_FLAGS_NON_BLOCKING bit in flags, the call will not return until either |
| 192 | * interruption or wakeup comes. |
192 | * timeout, interruption or wakeup comes. |
| 193 | * |
193 | * |
| 194 | * If usec is zero and the SYNCH_FLAGS_NON_BLOCKING bit is not set in flags, the call |
194 | * If usec is zero and the SYNCH_FLAGS_NON_BLOCKING bit is not set in flags, |
| 195 | * will not return until wakeup or interruption comes. |
195 | * the call will not return until wakeup or interruption comes. |
| 196 | * |
196 | * |
| 197 | * If usec is zero and the SYNCH_FLAGS_NON_BLOCKING bit is set in flags, the call will |
197 | * If usec is zero and the SYNCH_FLAGS_NON_BLOCKING bit is set in flags, the |
| 198 | * immediately return, reporting either success or failure. |
198 | * call will immediately return, reporting either success or failure. |
| 199 | * |
199 | * |
| 200 | * @return Returns one of: ESYNCH_WOULD_BLOCK, ESYNCH_TIMEOUT, ESYNCH_INTERRUPTED, |
200 | * @return One of: ESYNCH_WOULD_BLOCK, ESYNCH_TIMEOUT, ESYNCH_INTERRUPTED, |
| 201 | * ESYNCH_OK_ATOMIC, ESYNCH_OK_BLOCKED. |
201 | * ESYNCH_OK_ATOMIC, ESYNCH_OK_BLOCKED. |
| 202 | * |
202 | * |
| 203 | * @li ESYNCH_WOULD_BLOCK means that the sleep failed because at the time |
203 | * @li ESYNCH_WOULD_BLOCK means that the sleep failed because at the time of the |
| 204 | * of the call there was no pending wakeup. |
204 | * call there was no pending wakeup. |
| 205 | * |
205 | * |
| 206 | * @li ESYNCH_TIMEOUT means that the sleep timed out. |
206 | * @li ESYNCH_TIMEOUT means that the sleep timed out. |
| 207 | * |
207 | * |
| 208 | * @li ESYNCH_INTERRUPTED means that somebody interrupted the sleeping thread. |
208 | * @li ESYNCH_INTERRUPTED means that somebody interrupted the sleeping thread. |
| 209 | * |
209 | * |
| Line 349... | Line 349... | ||
| 349 | /* Short emulation of scheduler() return code. */ |
349 | /* Short emulation of scheduler() return code. */ |
| 350 | spinlock_unlock(&THREAD->lock); |
350 | spinlock_unlock(&THREAD->lock); |
| 351 | return ESYNCH_TIMEOUT; |
351 | return ESYNCH_TIMEOUT; |
| 352 | } |
352 | } |
| 353 | THREAD->timeout_pending = true; |
353 | THREAD->timeout_pending = true; |
| 354 | timeout_register(&THREAD->sleep_timeout, (uint64_t) usec, waitq_timeouted_sleep, THREAD); |
354 | timeout_register(&THREAD->sleep_timeout, (uint64_t) usec, |
| - | 355 | waitq_timeouted_sleep, THREAD); |
|
| 355 | } |
356 | } |
| 356 | 357 | ||
| 357 | list_append(&THREAD->wq_link, &wq->head); |
358 | list_append(&THREAD->wq_link, &wq->head); |
| 358 | 359 | ||
| 359 | /* |
360 | /* |
| Line 362... | Line 363... | ||
| 362 | THREAD->state = Sleeping; |
363 | THREAD->state = Sleeping; |
| 363 | THREAD->sleep_queue = wq; |
364 | THREAD->sleep_queue = wq; |
| 364 | 365 | ||
| 365 | spinlock_unlock(&THREAD->lock); |
366 | spinlock_unlock(&THREAD->lock); |
| 366 | 367 | ||
| 367 | scheduler(); /* wq->lock is released in scheduler_separated_stack() */ |
368 | /* wq->lock is released in scheduler_separated_stack() */ |
| - | 369 | scheduler(); |
|
| 368 | 370 | ||
| 369 | return ESYNCH_OK_BLOCKED; |
371 | return ESYNCH_OK_BLOCKED; |
| 370 | } |
372 | } |
| 371 | 373 | ||
| 372 | 374 | ||
| 373 | /** Wake up first thread sleeping in a wait queue |
375 | /** Wake up first thread sleeping in a wait queue |
| 374 | * |
376 | * |
| 375 | * Wake up first thread sleeping in a wait queue. |
377 | * Wake up first thread sleeping in a wait queue. This is the SMP- and IRQ-safe |
| 376 | * This is the SMP- and IRQ-safe wrapper meant for |
- | |
| 377 | * general use. |
378 | * wrapper meant for general use. |
| 378 | * |
379 | * |
| 379 | * Besides its 'normal' wakeup operation, it attempts |
380 | * Besides its 'normal' wakeup operation, it attempts to unregister possible |
| 380 | * to unregister possible timeout. |
381 | * timeout. |
| 381 | * |
382 | * |
| 382 | * @param wq Pointer to wait queue. |
383 | * @param wq Pointer to wait queue. |
| 383 | * @param all If this is non-zero, all sleeping threads |
384 | * @param all If this is non-zero, all sleeping threads will be woken up and |
| 384 | * will be woken up and missed count will be zeroed. |
385 | * missed count will be zeroed. |
| 385 | */ |
386 | */ |
| 386 | void waitq_wakeup(waitq_t *wq, bool all) |
387 | void waitq_wakeup(waitq_t *wq, bool all) |
| 387 | { |
388 | { |
| 388 | ipl_t ipl; |
389 | ipl_t ipl; |
| 389 | 390 | ||
| Line 396... | Line 397... | ||
| 396 | interrupts_restore(ipl); |
397 | interrupts_restore(ipl); |
| 397 | } |
398 | } |
| 398 | 399 | ||
| 399 | /** Internal SMP- and IRQ-unsafe version of waitq_wakeup() |
400 | /** Internal SMP- and IRQ-unsafe version of waitq_wakeup() |
| 400 | * |
401 | * |
| 401 | * This is the internal SMP- and IRQ-unsafe version |
402 | * This is the internal SMP- and IRQ-unsafe version of waitq_wakeup(). It |
| 402 | * of waitq_wakeup(). It assumes wq->lock is already |
- | |
| 403 | * locked and interrupts are already disabled. |
403 | * assumes wq->lock is already locked and interrupts are already disabled. |
| 404 | * |
404 | * |
| 405 | * @param wq Pointer to wait queue. |
405 | * @param wq Pointer to wait queue. |
| 406 | * @param all If this is non-zero, all sleeping threads |
406 | * @param all If this is non-zero, all sleeping threads will be woken up and |
| 407 | * will be woken up and missed count will be zeroed. |
407 | * missed count will be zeroed. |
| 408 | */ |
408 | */ |
| 409 | void _waitq_wakeup_unsafe(waitq_t *wq, bool all) |
409 | void _waitq_wakeup_unsafe(waitq_t *wq, bool all) |
| 410 | { |
410 | { |
| 411 | thread_t *t; |
411 | thread_t *t; |
| 412 | 412 | ||