src/ppe/pk/kernel/pk_thread_core.c
// This routine is only used locally.  Interrupts must be disabled
// at entry.  The caller must also have checked that the priority is free.
// This routine is only called on threads known to be in a suspended state,
// either PK_THREAD_STATE_SUSPENDED_RUNNABLE or
// PK_THREAD_STATE_SUSPENDED_BLOCKED.  Mapping a runnable thread adds it to
// the run queue.  Mapping a thread pending on a semaphore either takes the
// count and becomes runnable or adds the thread to the pending queue for the
// semaphore.  Mapping a sleeping thread requires no further action
// here. Scheduling after the map must be handled by the caller.
This routine is only used locally.  Interrupts must be disabled
at entry.  The caller must also have checked that the priority is free.
This routine is only called on threads known to be in a suspended state,
either PK_THREAD_STATE_SUSPENDED_RUNNABLE or
PK_THREAD_STATE_SUSPENDED_BLOCKED.  Mapping a runnable thread adds it to
the run queue.  Mapping a thread pending on a semaphore either takes the
count and becomes runnable or adds the thread to the pending queue for the
semaphore.  Mapping a sleeping thread requires no further action
here. Scheduling after the map must be handled by the caller.
This routine is only used locally . Interrupts must be disabled at entry . The caller must also have checked that the priority is free . This routine is only called on threads known to be in a suspended state either PK_THREAD_STATE_SUSPENDED_RUNNABLE or PK_THREAD_STATE_SUSPENDED_BLOCKED . Mapping a runnable thread adds it to the run queue . Mapping a thread pending on a semaphore either takes the count and becomes runnable or adds the thread to the pending queue for the semaphore . Mapping a sleeping thread requires no further action here . Scheduling after the map must be handled by the caller .
void
__pk_thread_map(PkThread* thread)
{
    PkThreadPriority priority;
    priority = thread->priority;
    __pk_priority_map[priority] = thread;
    if (thread->state == PK_THREAD_STATE_SUSPENDED_RUNNABLE) {
        __pk_thread_queue_insert(&__pk_run_queue, priority);
    } else if (thread->flags & PK_THREAD_FLAG_SEMAPHORE_PEND) {
        if (thread->semaphore->count) {
            thread->semaphore->count--;
            __pk_thread_queue_insert(&__pk_run_queue, priority);
        } else {
            __pk_thread_queue_insert(&(thread->semaphore->pending_threads),
                                      priority);
        }
    }
    thread->state = PK_THREAD_STATE_MAPPED;
    if (PK_KERNEL_TRACE_ENABLE) {
        if (__pk_thread_is_runnable(thread)) {
            PK_KERN_TRACE("THREAD_MAPPED_RUNNABLE(%d)", priority);
        } else if (thread->flags & PK_THREAD_FLAG_SEMAPHORE_PEND) {
            PK_KERN_TRACE("THREAD_MAPPED_SEMAPHORE_PEND(%d)", priority);
        } else {
            PK_KERN_TRACE("THREAD_MAPPED_SLEEPING(%d)", priority);
        }
    }
}
void __pk_thread_map ( PkThread * thread ) { PkThreadPriority priority ; priority = thread -> priority ; __pk_priority_map [ priority ] = thread ; if ( thread -> state == PK_THREAD_STATE_SUSPENDED_RUNNABLE ) { __pk_thread_queue_insert ( & __pk_run_queue , priority ) ; } else if ( thread -> flags & PK_THREAD_FLAG_SEMAPHORE_PEND ) { if ( thread -> semaphore -> count ) { thread -> semaphore -> count -- ; __pk_thread_queue_insert ( & __pk_run_queue , priority ) ; } else { __pk_thread_queue_insert ( & ( thread -> semaphore -> pending_threads ) , priority ) ; } } thread -> state = PK_THREAD_STATE_MAPPED ; if ( PK_KERNEL_TRACE_ENABLE ) { if ( __pk_thread_is_runnable ( thread ) ) { PK_KERN_TRACE ( " " , priority ) ; } else if ( thread -> flags & PK_THREAD_FLAG_SEMAPHORE_PEND ) { PK_KERN_TRACE ( " " , priority ) ; } else { PK_KERN_TRACE ( " " , priority ) ; } } }
This routine is only used locally.
This routine is only used locally .