Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/src/synch/condvar.c

    r111b9b9 re88eb48  
    5858void condvar_signal(condvar_t *cv)
    5959{
    60         waitq_signal(&cv->wq);
     60        waitq_wakeup(&cv->wq, WAKEUP_FIRST);
    6161}
    6262
     
    6868void condvar_broadcast(condvar_t *cv)
    6969{
    70         waitq_wake_all(&cv->wq);
     70        waitq_wakeup(&cv->wq, WAKEUP_ALL);
    7171}
    7272
     
    7676 * @param mtx           Mutex.
    7777 * @param usec          Timeout value in microseconds.
     78 * @param flags         Select mode of operation.
     79 *
     80 * For exact description of meaning of possible combinations of usec and flags,
     81 * see comment for waitq_sleep_timeout().  Note that when
     82 * SYNCH_FLAGS_NON_BLOCKING is specified here, EAGAIN is always
     83 * returned.
    7884 *
    7985 * @return              See comment for waitq_sleep_timeout().
    8086 */
    81 errno_t condvar_wait_timeout(condvar_t *cv, mutex_t *mtx, uint32_t usec)
     87errno_t _condvar_wait_timeout(condvar_t *cv, mutex_t *mtx, uint32_t usec, int flags)
    8288{
    83         wait_guard_t guard = waitq_sleep_prepare(&cv->wq);
     89        errno_t rc;
     90        ipl_t ipl;
     91        bool blocked;
    8492
     93        ipl = waitq_sleep_prepare(&cv->wq);
    8594        /* Unlock only after the waitq is locked so we don't miss a wakeup. */
    8695        mutex_unlock(mtx);
    8796
    88         errno_t rc = waitq_sleep_timeout_unsafe(&cv->wq, usec, SYNCH_FLAGS_NON_BLOCKING, guard);
     97        cv->wq.missed_wakeups = 0;      /* Enforce blocking. */
     98        rc = waitq_sleep_timeout_unsafe(&cv->wq, usec, flags, &blocked);
     99        assert(blocked || rc != EOK);
    89100
     101        waitq_sleep_finish(&cv->wq, blocked, ipl);
     102        /* Lock only after releasing the waitq to avoid a possible deadlock. */
    90103        mutex_lock(mtx);
    91         return rc;
    92 }
    93104
    94 errno_t condvar_wait(condvar_t *cv, mutex_t *mtx)
    95 {
    96         wait_guard_t guard = waitq_sleep_prepare(&cv->wq);
    97 
    98         /* Unlock only after the waitq is locked so we don't miss a wakeup. */
    99         mutex_unlock(mtx);
    100 
    101         errno_t rc = waitq_sleep_unsafe(&cv->wq, guard);
    102 
    103         mutex_lock(mtx);
    104105        return rc;
    105106}
     
    126127    uint32_t usec, int flags)
    127128{
    128         wait_guard_t guard = waitq_sleep_prepare(&cv->wq);
     129        errno_t rc;
     130        ipl_t ipl;
     131        bool blocked;
     132
     133        ipl = waitq_sleep_prepare(&cv->wq);
    129134
    130135        /* Unlock only after the waitq is locked so we don't miss a wakeup. */
    131136        spinlock_unlock(lock);
    132137
    133         errno_t rc = waitq_sleep_timeout_unsafe(&cv->wq, usec, flags, guard);
     138        cv->wq.missed_wakeups = 0;      /* Enforce blocking. */
     139        rc = waitq_sleep_timeout_unsafe(&cv->wq, usec, flags, &blocked);
     140        assert(blocked || rc != EOK);
    134141
     142        waitq_sleep_finish(&cv->wq, blocked, ipl);
     143        /* Lock only after releasing the waitq to avoid a possible deadlock. */
    135144        spinlock_lock(lock);
     145
    136146        return rc;
    137147}
Note: See TracChangeset for help on using the changeset viewer.