Changeset 116d1ef4 in mainline for generic/src/synch/waitq.c


Ignore:
Timestamp:
2006-06-02T12:26:50Z (18 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
d0c5901
Parents:
01ebbdf
Message:

Replace nonblocking argument of waitq_sleep_timeout with flags that specify mode of operation.
Now a flag can be used to specify interruptible sleep.
Modify waitq_interrupt_sleep() to only interrupt threads that used this flag.
O

File:
1 edited

Legend:

Unmodified
Added
Removed
  • generic/src/synch/waitq.c

    r01ebbdf r116d1ef4  
    136136        spinlock_lock(&t->lock);
    137137        if ((wq = t->sleep_queue)) {            /* assignment */
     138                if (!(t->sleep_interruptible)) {
     139                        /*
     140                         * The sleep cannot be interrupted.
     141                         */
     142                        spinlock_unlock(&t->lock);
     143                        goto out;
     144                }
     145                       
    138146                if (!spinlock_trylock(&wq->lock)) {
    139147                        spinlock_unlock(&t->lock);
     
    160168/** Sleep until either wakeup, timeout or interruption occurs
    161169 *
    162  * This is a sleep implementation which allows itself to be
     170 * This is a sleep implementation which allows itself to time out or to be
    163171 * interrupted from the sleep, restoring a failover context.
    164172 *
     
    170178 * @param wq Pointer to wait queue.
    171179 * @param usec Timeout in microseconds.
    172  * @param nonblocking Blocking vs. non-blocking operation mode switch.
    173  *
    174  * If usec is greater than zero, regardless of the value of nonblocking,
    175  * the call will not return until either timeout or wakeup comes.
    176  *
    177  * If usec is zero and @nonblocking is zero (false), the call
    178  * will not return until wakeup comes.
    179  *
    180  * If usec is zero and nonblocking is non-zero (true), the call will
     180 * @param flags Specify mode of the sleep.
     181 *
     182 * The sleep can be interrupted only if the
     183 * SYNCH_FLAGS_INTERRUPTIBLE bit is specified in flags.
     184 
     185 * If usec is greater than zero, regardless of the value of the
     186 * SYNCH_FLAGS_NON_BLOCKING bit in flags, the call will not return until either timeout,
     187 * interruption or wakeup comes.
     188 *
     189 * If usec is zero and the SYNCH_FLAGS_NON_BLOCKING bit is not set in flags, the call
     190 * will not return until wakeup or interruption comes.
     191 *
     192 * If usec is zero and the SYNCH_FLAGS_NON_BLOCKING bit is set in flags, the call will
    181193 * immediately return, reporting either success or failure.
    182194 *
    183  * @return      Returns one of: ESYNCH_WOULD_BLOCK, ESYNCH_TIMEOUT,
     195 * @return      Returns one of: ESYNCH_WOULD_BLOCK, ESYNCH_TIMEOUT, ESYNCH_INTERRUPTED,
    184196 *              ESYNCH_OK_ATOMIC, ESYNCH_OK_BLOCKED.
    185197 *
     
    198210 * attempted.
    199211 */
    200 int waitq_sleep_timeout(waitq_t *wq, __u32 usec, int nonblocking)
     212int waitq_sleep_timeout(waitq_t *wq, __u32 usec, int flags)
    201213{
    202214        ipl_t ipl;
     
    204216       
    205217        ipl = waitq_sleep_prepare(wq);
    206         rc = waitq_sleep_timeout_unsafe(wq, usec, nonblocking);
     218        rc = waitq_sleep_timeout_unsafe(wq, usec, flags);
    207219        waitq_sleep_finish(wq, rc, ipl);
    208220        return rc;
     
    277289 * @param wq See waitq_sleep_timeout().
    278290 * @param usec See waitq_sleep_timeout().
    279  * @param nonblocking See waitq_sleep_timeout().
     291 * @param flags See waitq_sleep_timeout().
    280292 *
    281293 * @return See waitq_sleep_timeout().
    282294 */
    283 int waitq_sleep_timeout_unsafe(waitq_t *wq, __u32 usec, int nonblocking)
     295int waitq_sleep_timeout_unsafe(waitq_t *wq, __u32 usec, int flags)
    284296{
    285297        /* checks whether to go to sleep at all */
     
    289301        }
    290302        else {
    291                 if (nonblocking && (usec == 0)) {
     303                if ((flags & SYNCH_FLAGS_NON_BLOCKING) && (usec == 0)) {
    292304                        /* return immediatelly instead of going to sleep */
    293305                        return ESYNCH_WOULD_BLOCK;
     
    300312        spinlock_lock(&THREAD->lock);
    301313
    302         /*
    303          * Set context that will be restored if the sleep
    304          * of this thread is ever interrupted.
    305          */
    306         if (!context_save(&THREAD->sleep_interruption_context)) {
    307                 /* Short emulation of scheduler() return code. */
    308                 spinlock_unlock(&THREAD->lock);
    309                 return ESYNCH_INTERRUPTED;
     314        if (flags & SYNCH_FLAGS_INTERRUPTIBLE) {
     315                /*
     316                 * Set context that will be restored if the sleep
     317                 * of this thread is ever interrupted.
     318                 */
     319                THREAD->sleep_interruptible = true;
     320                if (!context_save(&THREAD->sleep_interruption_context)) {
     321                        /* Short emulation of scheduler() return code. */
     322                        spinlock_unlock(&THREAD->lock);
     323                        return ESYNCH_INTERRUPTED;
     324                }
     325        } else {
     326                THREAD->sleep_interruptible = false;
    310327        }
    311328
Note: See TracChangeset for help on using the changeset viewer.