Fork us on GitHub Follow us on Facebook Follow us on Twitter

Changeset 3954961e in mainline


Ignore:
Timestamp:
2012-07-10T17:34:22Z (10 years ago)
Author:
Adam Hraska <adam.hraska+hos@…>
Branches:
lfn, master, serial
Children:
e0c80f66
Parents:
ff90f5f
Message:

waitq: Added ability to wait for the completion of a running wakeup.

Location:
kernel/generic
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/include/synch/waitq.h

    rff90f5f r3954961e  
    7777extern void waitq_sleep_finish(waitq_t *, int, ipl_t);
    7878extern void waitq_wakeup(waitq_t *, wakeup_mode_t);
     79extern void waitq_complete_wakeup(waitq_t *);
    7980extern void _waitq_wakeup_unsafe(waitq_t *, wakeup_mode_t);
    8081extern void waitq_interrupt_sleep(struct thread *);
  • kernel/generic/src/synch/waitq.c

    rff90f5f r3954961e  
    442442        irq_spinlock_unlock(&wq->lock, true);
    443443}
     444
     445/** If there is a wakeup in progress actively waits for it to complete.
     446 *
     447 * The function returns once the concurrently running waitq_wakeup()
     448 * exits. It returns immediately if there are no concurrent wakeups
     449 * at the time.
     450 *
     451 * Example usage:
     452 * @code
     453 * void callback(waitq *wq)
     454 * {
     455 *     // Do something and notify wait_for_completion() that we're done.
     456 *     waitq_wakeup(wq);
     457 * }
     458 * void wait_for_completion(void)
     459 * {
     460 *     waitq wg;
     461 *     waitq_initialize(&wq);
     462 *     // Run callback() in the background, pass it wq.
     463 *     do_asynchronously(callback, &wq);
     464 *     // Wait for callback() to complete its work.
     465 *     waitq_sleep(&wq);
     466 *     // callback() completed its work, but it may still be accessing
     467 *     // wq in waitq_wakeup(). Therefore it is not yet safe to return
     468 *     // or it would clobber up our stack (where wq is stored).
     469 *     waitq_complete_wakeup(&wq);
     470 *     // waitq_wakeup() is complete, it is safe to free wq.
     471 * }
     472 * @endcode
     473 *
     474 * @param wq  Pointer to a wait queue.
     475 */
     476void waitq_complete_wakeup(waitq_t *wq)
     477{
     478        irq_spinlock_lock(&wq->lock, true);
     479        irq_spinlock_unlock(&wq->lock, true);
     480}
     481
    444482
    445483/** Internal SMP- and IRQ-unsafe version of waitq_wakeup()
Note: See TracChangeset for help on using the changeset viewer.