Changeset 3954961e in mainline for kernel/generic/src/synch/waitq.c


Ignore:
Timestamp:
2012-07-10T17:34:22Z (12 years ago)
Author:
Adam Hraska <adam.hraska+hos@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
e0c80f66
Parents:
ff90f5f
Message:

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.