Changeset 5c8ba05 in mainline


Ignore:
Timestamp:
2007-05-07T18:52:24Z (18 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
6fa4888b
Parents:
4f42d52
Message:

Cleanup the waitq_wakeup() interface.
Replace numeric constants (i.e. 0)
and boolean constants (i.e. false) with
more readable WAKEUP_FIRST. Also change the
type of the second argument of waitq_wakeup()
to a newly introduced type wakeup_mode_t.

Fix behaviour of waitq_wakeup() in case
that WAKEUP_ALL semantics is required
but no threads are sleeping in the wait
queue. This is a similar fix to that of
Jan Hudecek committed in the RCU branch,
but, IMHO, is more straightforward and
also doesn't eat up previous missed
wakeups.

Location:
kernel/generic
Files:
4 edited

Legend:

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

    r4f42d52 r5c8ba05  
    4141#include <adt/list.h>
    4242
    43 #define WAKEUP_FIRST    0
    44 #define WAKEUP_ALL      1
     43typedef enum {
     44        WAKEUP_FIRST = 0,
     45        WAKEUP_ALL
     46} wakeup_mode_t;
    4547
    4648/** Wait queue structure. */
     
    7173extern int waitq_sleep_timeout_unsafe(waitq_t *wq, uint32_t usec, int flags);
    7274extern void waitq_sleep_finish(waitq_t *wq, int rc, ipl_t ipl);
    73 extern void waitq_wakeup(waitq_t *wq, bool all);
    74 extern void _waitq_wakeup_unsafe(waitq_t *wq, bool all);
     75extern void waitq_wakeup(waitq_t *wq, wakeup_mode_t mode);
     76extern void _waitq_wakeup_unsafe(waitq_t *wq, wakeup_mode_t mode);
    7577extern void waitq_interrupt_sleep(struct thread *t);
    7678
  • kernel/generic/src/ipc/ipc.c

    r4f42d52 r5c8ba05  
    164164        list_append(&call->link, &callerbox->answers);
    165165        spinlock_unlock(&callerbox->lock);
    166         waitq_wakeup(&callerbox->wq, 0);
     166        waitq_wakeup(&callerbox->wq, WAKEUP_FIRST);
    167167}
    168168
     
    206206        list_append(&call->link, &box->calls);
    207207        spinlock_unlock(&box->lock);
    208         waitq_wakeup(&box->wq, 0);
     208        waitq_wakeup(&box->wq, WAKEUP_FIRST);
    209209}
    210210
  • kernel/generic/src/proc/scheduler.c

    r4f42d52 r5c8ba05  
    412412                                        goto repeat;
    413413                                }
    414                                 _waitq_wakeup_unsafe(&THREAD->join_wq, false);
     414                                _waitq_wakeup_unsafe(&THREAD->join_wq,
     415                                    WAKEUP_FIRST);
    415416                                spinlock_unlock(&THREAD->join_wq.lock);
    416417                               
  • kernel/generic/src/synch/waitq.c

    r4f42d52 r5c8ba05  
    384384 * timeout.
    385385 *
    386  * @param wq Pointer to wait queue.
    387  * @param all If this is non-zero, all sleeping threads will be woken up and
    388  *      missed count will be zeroed.
    389  */
    390 void waitq_wakeup(waitq_t *wq, bool all)
     386 * @param wq    Pointer to wait queue.
     387 * @param mode  Wakeup mode.
     388 */
     389void waitq_wakeup(waitq_t *wq, wakeup_mode_t mode)
    391390{
    392391        ipl_t ipl;
     
    395394        spinlock_lock(&wq->lock);
    396395
    397         _waitq_wakeup_unsafe(wq, all);
    398 
    399         spinlock_unlock(&wq->lock);     
    400         interrupts_restore(ipl);       
     396        _waitq_wakeup_unsafe(wq, mode);
     397
     398        spinlock_unlock(&wq->lock);
     399        interrupts_restore(ipl);
    401400}
    402401
     
    406405 * assumes wq->lock is already locked and interrupts are already disabled.
    407406 *
    408  * @param wq Pointer to wait queue.
    409  * @param all If this is non-zero, all sleeping threads will be woken up and
    410  *      missed count will be zeroed.
    411  */
    412 void _waitq_wakeup_unsafe(waitq_t *wq, bool all)
     407 * @param wq    Pointer to wait queue.
     408 * @param mode  If mode is WAKEUP_FIRST, then the longest waiting thread,
     409 *              if any, is woken up. If mode is WAKEUP_ALL, then all
     410 *              waiting threads, if any, are woken up. If there are no
     411 *              waiting threads to be woken up, the missed wakeup is
     412 *              recorded in the wait queue.
     413 */
     414void _waitq_wakeup_unsafe(waitq_t *wq, wakeup_mode_t mode)
    413415{
    414416        thread_t *t;
     417        count_t count = 0;
    415418
    416419loop:   
    417420        if (list_empty(&wq->head)) {
    418421                wq->missed_wakeups++;
    419                 if (all)
    420                         wq->missed_wakeups = 0;
     422                if (count && mode == WAKEUP_ALL)
     423                        wq->missed_wakeups--;
    421424                return;
    422425        }
    423426
     427        count++;
    424428        t = list_get_instance(wq->head.next, thread_t, wq_link);
    425429       
     
    450454        thread_ready(t);
    451455
    452         if (all)
     456        if (mode == WAKEUP_ALL)
    453457                goto loop;
    454458}
Note: See TracChangeset for help on using the changeset viewer.