Ignore:
File:
1 edited

Legend:

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

    r1b20da0 ra35b458  
    9494        bool do_wakeup = false;
    9595        DEADLOCK_PROBE_INIT(p_wqlock);
    96        
     96
    9797        irq_spinlock_lock(&threads_lock, false);
    9898        if (!thread_exists(thread))
    9999                goto out;
    100        
     100
    101101grab_locks:
    102102        irq_spinlock_lock(&thread->lock, false);
    103        
     103
    104104        waitq_t *wq;
    105105        if ((wq = thread->sleep_queue)) {  /* Assignment */
     
    110110                        goto grab_locks;
    111111                }
    112                
     112
    113113                list_remove(&thread->wq_link);
    114114                thread->saved_context = thread->sleep_timeout_context;
     
    117117                irq_spinlock_unlock(&wq->lock, false);
    118118        }
    119        
     119
    120120        thread->timeout_pending = false;
    121121        irq_spinlock_unlock(&thread->lock, false);
    122        
     122
    123123        if (do_wakeup)
    124124                thread_ready(thread);
    125        
     125
    126126out:
    127127        irq_spinlock_unlock(&threads_lock, false);
     
    144144        bool do_wakeup = false;
    145145        DEADLOCK_PROBE_INIT(p_wqlock);
    146        
     146
    147147        /*
    148148         * The thread is quaranteed to exist because
    149149         * threads_lock is held.
    150150         */
    151        
     151
    152152grab_locks:
    153153        irq_spinlock_lock(&thread->lock, false);
    154        
     154
    155155        waitq_t *wq;
    156156        if ((wq = thread->sleep_queue)) {  /* Assignment */
     
    162162                        return;
    163163                }
    164                
     164
    165165                if (!irq_spinlock_trylock(&wq->lock)) {
    166166                        /* Avoid deadlock */
     
    169169                        goto grab_locks;
    170170                }
    171                
     171
    172172                if ((thread->timeout_pending) &&
    173173                    (timeout_unregister(&thread->sleep_timeout)))
    174174                        thread->timeout_pending = false;
    175                
     175
    176176                list_remove(&thread->wq_link);
    177177                thread->saved_context = thread->sleep_interruption_context;
     
    180180                irq_spinlock_unlock(&wq->lock, false);
    181181        }
    182        
     182
    183183        irq_spinlock_unlock(&thread->lock, false);
    184        
     184
    185185        if (do_wakeup)
    186186                thread_ready(thread);
     
    198198{
    199199        irq_spinlock_lock(&wq->lock, true);
    200        
     200
    201201        if (!list_empty(&wq->sleepers)) {
    202202                thread_t *thread = list_get_instance(list_first(&wq->sleepers),
    203203                    thread_t, wq_link);
    204                
     204
    205205                irq_spinlock_lock(&thread->lock, false);
    206                
     206
    207207                assert(thread->sleep_interruptible);
    208                
     208
    209209                if ((thread->timeout_pending) &&
    210210                    (timeout_unregister(&thread->sleep_timeout)))
    211211                        thread->timeout_pending = false;
    212                
     212
    213213                list_remove(&thread->wq_link);
    214214                thread->saved_context = thread->sleep_interruption_context;
    215215                thread->sleep_queue = NULL;
    216                
     216
    217217                irq_spinlock_unlock(&thread->lock, false);
    218218                thread_ready(thread);
    219219        }
    220        
     220
    221221        irq_spinlock_unlock(&wq->lock, true);
    222222}
     
    271271{
    272272        assert((!PREEMPTION_DISABLED) || (PARAM_NON_BLOCKING(flags, usec)));
    273        
     273
    274274        ipl_t ipl = waitq_sleep_prepare(wq);
    275275        bool nblocked;
     
    296296{
    297297        ipl_t ipl;
    298        
     298
    299299restart:
    300300        ipl = interrupts_disable();
    301        
     301
    302302        if (THREAD) {  /* Needed during system initiailzation */
    303303                /*
     
    310310                 */
    311311                irq_spinlock_lock(&THREAD->lock, false);
    312                
     312
    313313                if (THREAD->timeout_pending) {
    314314                        irq_spinlock_unlock(&THREAD->lock, false);
     
    316316                        goto restart;
    317317                }
    318                
     318
    319319                irq_spinlock_unlock(&THREAD->lock, false);
    320320        }
    321        
     321
    322322        irq_spinlock_lock(&wq->lock, false);
    323323        return ipl;
     
    354354                irq_spinlock_unlock(&wq->lock, false);
    355355        }
    356        
     356
    357357        interrupts_restore(ipl);
    358358}
     
    387387                }
    388388        }
    389        
     389
    390390        /*
    391391         * Now we are firmly decided to go to sleep.
     
    393393         */
    394394        irq_spinlock_lock(&THREAD->lock, false);
    395        
     395
    396396        if (flags & SYNCH_FLAGS_INTERRUPTIBLE) {
    397397                /*
     
    403403                        return EINTR;
    404404                }
    405                
     405
    406406                /*
    407407                 * Set context that will be restored if the sleep
     
    417417        } else
    418418                THREAD->sleep_interruptible = false;
    419        
     419
    420420        if (usec) {
    421421                /* We use the timeout variant. */
     
    426426                        return ETIMEOUT;
    427427                }
    428                
     428
    429429                THREAD->timeout_pending = true;
    430430                timeout_register(&THREAD->sleep_timeout, (uint64_t) usec,
    431431                    waitq_sleep_timed_out, THREAD);
    432432        }
    433        
     433
    434434        list_append(&THREAD->wq_link, &wq->sleepers);
    435        
     435
    436436        /*
    437437         * Suspend execution.
     
    440440        THREAD->state = Sleeping;
    441441        THREAD->sleep_queue = wq;
    442        
     442
    443443        /* Must be before entry to scheduler, because there are multiple
    444444         * return vectors.
    445445         */
    446446        *blocked = true;
    447        
     447
    448448        irq_spinlock_unlock(&THREAD->lock, false);
    449        
     449
    450450        /* wq->lock is released in scheduler_separated_stack() */
    451451        scheduler();
    452        
     452
    453453        return EOK;
    454454}
     
    511511{
    512512        assert(interrupts_disabled());
    513        
     513
    514514        irq_spinlock_lock(&wq->lock, false);
    515515        irq_spinlock_unlock(&wq->lock, false);
     
    536536        assert(interrupts_disabled());
    537537        assert(irq_spinlock_locked(&wq->lock));
    538        
     538
    539539loop:
    540540        if (list_empty(&wq->sleepers)) {
     
    542542                if ((count) && (mode == WAKEUP_ALL))
    543543                        wq->missed_wakeups--;
    544                
     544
    545545                return;
    546546        }
    547        
     547
    548548        count++;
    549549        thread_t *thread = list_get_instance(list_first(&wq->sleepers),
    550550            thread_t, wq_link);
    551        
     551
    552552        /*
    553553         * Lock the thread prior to removing it from the wq.
     
    569569        irq_spinlock_lock(&thread->lock, false);
    570570        list_remove(&thread->wq_link);
    571        
     571
    572572        if ((thread->timeout_pending) &&
    573573            (timeout_unregister(&thread->sleep_timeout)))
    574574                thread->timeout_pending = false;
    575        
     575
    576576        thread->sleep_queue = NULL;
    577577        irq_spinlock_unlock(&thread->lock, false);
    578        
     578
    579579        thread_ready(thread);
    580        
     580
    581581        if (mode == WAKEUP_ALL)
    582582                goto loop;
Note: See TracChangeset for help on using the changeset viewer.