Rev 2183 | Rev 2909 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 2183 | Rev 2310 | ||
|---|---|---|---|
| Line 381... | Line 381... | ||
| 381 | * wrapper meant for general use. |
381 | * wrapper meant for general use. |
| 382 | * |
382 | * |
| 383 | * Besides its 'normal' wakeup operation, it attempts to unregister possible |
383 | * Besides its 'normal' wakeup operation, it attempts to unregister possible |
| 384 | * timeout. |
384 | * timeout. |
| 385 | * |
385 | * |
| 386 | * @param wq Pointer to wait queue. |
386 | * @param wq Pointer to wait queue. |
| 387 | * @param all If this is non-zero, all sleeping threads will be woken up and |
- | |
| 388 | * missed count will be zeroed. |
387 | * @param mode Wakeup mode. |
| 389 | */ |
388 | */ |
| 390 | void waitq_wakeup(waitq_t *wq, bool all) |
389 | void waitq_wakeup(waitq_t *wq, wakeup_mode_t mode) |
| 391 | { |
390 | { |
| 392 | ipl_t ipl; |
391 | ipl_t ipl; |
| 393 | 392 | ||
| 394 | ipl = interrupts_disable(); |
393 | ipl = interrupts_disable(); |
| 395 | spinlock_lock(&wq->lock); |
394 | spinlock_lock(&wq->lock); |
| 396 | 395 | ||
| 397 | _waitq_wakeup_unsafe(wq, all); |
396 | _waitq_wakeup_unsafe(wq, mode); |
| 398 | 397 | ||
| 399 | spinlock_unlock(&wq->lock); |
398 | spinlock_unlock(&wq->lock); |
| 400 | interrupts_restore(ipl); |
399 | interrupts_restore(ipl); |
| 401 | } |
400 | } |
| 402 | 401 | ||
| 403 | /** Internal SMP- and IRQ-unsafe version of waitq_wakeup() |
402 | /** Internal SMP- and IRQ-unsafe version of waitq_wakeup() |
| 404 | * |
403 | * |
| 405 | * This is the internal SMP- and IRQ-unsafe version of waitq_wakeup(). It |
404 | * 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. |
405 | * assumes wq->lock is already locked and interrupts are already disabled. |
| 407 | * |
406 | * |
| 408 | * @param wq Pointer to wait queue. |
407 | * @param wq Pointer to wait queue. |
| 409 | * @param all If this is non-zero, all sleeping threads will be woken up and |
408 | * @param mode If mode is WAKEUP_FIRST, then the longest waiting thread, |
| - | 409 | * if any, is woken up. If mode is WAKEUP_ALL, then all |
|
| - | 410 | * waiting threads, if any, are woken up. If there are no |
|
| - | 411 | * waiting threads to be woken up, the missed wakeup is |
|
| 410 | * missed count will be zeroed. |
412 | * recorded in the wait queue. |
| 411 | */ |
413 | */ |
| 412 | void _waitq_wakeup_unsafe(waitq_t *wq, bool all) |
414 | void _waitq_wakeup_unsafe(waitq_t *wq, wakeup_mode_t mode) |
| 413 | { |
415 | { |
| 414 | thread_t *t; |
416 | thread_t *t; |
| - | 417 | count_t count = 0; |
|
| 415 | 418 | ||
| 416 | loop: |
419 | loop: |
| 417 | if (list_empty(&wq->head)) { |
420 | if (list_empty(&wq->head)) { |
| 418 | wq->missed_wakeups++; |
421 | wq->missed_wakeups++; |
| 419 | if (all) |
422 | if (count && mode == WAKEUP_ALL) |
| 420 | wq->missed_wakeups = 0; |
423 | wq->missed_wakeups--; |
| 421 | return; |
424 | return; |
| 422 | } |
425 | } |
| 423 | 426 | ||
| - | 427 | count++; |
|
| 424 | t = list_get_instance(wq->head.next, thread_t, wq_link); |
428 | t = list_get_instance(wq->head.next, thread_t, wq_link); |
| 425 | 429 | ||
| 426 | /* |
430 | /* |
| 427 | * Lock the thread prior to removing it from the wq. |
431 | * Lock the thread prior to removing it from the wq. |
| 428 | * This is not necessary because of mutual exclusion |
432 | * This is not necessary because of mutual exclusion |
| Line 447... | Line 451... | ||
| 447 | t->sleep_queue = NULL; |
451 | t->sleep_queue = NULL; |
| 448 | spinlock_unlock(&t->lock); |
452 | spinlock_unlock(&t->lock); |
| 449 | 453 | ||
| 450 | thread_ready(t); |
454 | thread_ready(t); |
| 451 | 455 | ||
| 452 | if (all) |
456 | if (mode == WAKEUP_ALL) |
| 453 | goto loop; |
457 | goto loop; |
| 454 | } |
458 | } |
| 455 | 459 | ||
| 456 | /** @} |
460 | /** @} |
| 457 | */ |
461 | */ |