src/ppe/pk/kernel/pk_thread_core.c
// Generic thread timeout
//
// This routine is called as a timer callback either because a sleeping thread
// has timed out or a thread pending on a semaphore has timed out.  If the
// thread is not already runnable then the the timeout flag is set, and if the
// thread is mapped it is scheduled.
//
// This implementation allows that a thread blocked on a timer may have been
// made runnable by some other mechanism, such as acquiring a semaphore.  In
// order to provide an iteration-free implementation of
// pk_semaphore_release_all(), cancelling any semaphore timeouts is deferred
// until the thread runs again.
//
// Note that we do not create trace events for unmapped threads since the trace
// tag only encodes the priority, which may be in use by a mapped thread.
Generic thread timeout
This routine is called as a timer callback either because a sleeping thread
has timed out or a thread pending on a semaphore has timed out.  If the
thread is not already runnable then the the timeout flag is set, and if the
thread is mapped it is scheduled.

This implementation allows that a thread blocked on a timer may have been
made runnable by some other mechanism, such as acquiring a semaphore.  In
order to provide an iteration-free implementation of
pk_semaphore_release_all(), cancelling any semaphore timeouts is deferred
until the thread runs again.

Note that we do not create trace events for unmapped threads since the trace
tag only encodes the priority, which may be in use by a mapped thread.
Generic thread timeout This routine is called as a timer callback either because a sleeping thread has timed out or a thread pending on a semaphore has timed out . If the thread is not already runnable then the the timeout flag is set and if the thread is mapped it is scheduled . This implementation allows that a thread blocked on a timer may have been made runnable by some other mechanism such as acquiring a semaphore . In order to provide an iteration - free implementation of pk_semaphore_release_all () cancelling any semaphore timeouts is deferred until the thread runs again . Note that we do not create trace events for unmapped threads since the trace tag only encodes the priority which may be in use by a mapped thread .
void
__pk_thread_timeout(void *arg)
{
    PkMachineContext ctx;
    PkThread *thread = (PkThread *)arg;
    pk_critical_section_enter(&ctx);
    switch (thread->state) {
    case PK_THREAD_STATE_MAPPED:
        if (!__pk_thread_is_runnable(thread)) {
            thread->flags |= PK_THREAD_FLAG_TIMED_OUT;
            __pk_thread_queue_insert(&__pk_run_queue, thread->priority);
            __pk_schedule();
        }
        break;
    case PK_THREAD_STATE_SUSPENDED_RUNNABLE:
        break;
    case PK_THREAD_STATE_SUSPENDED_BLOCKED:
        thread->flags |= PK_THREAD_FLAG_TIMED_OUT;
        thread->state = PK_THREAD_STATE_SUSPENDED_RUNNABLE;
        break;
    default:
        PK_PANIC(PK_THREAD_TIMEOUT_STATE);
    }
    pk_critical_section_exit(&ctx);
}
void __pk_thread_timeout ( void * arg ) { PkMachineContext ctx ; PkThread * thread = ( PkThread * ) arg ; pk_critical_section_enter ( & ctx ) ; switch ( thread -> state ) { case PK_THREAD_STATE_MAPPED : if ( ! __pk_thread_is_runnable ( thread ) ) { thread -> flags |= PK_THREAD_FLAG_TIMED_OUT ; __pk_thread_queue_insert ( & __pk_run_queue , thread -> priority ) ; __pk_schedule ( ) ; } break ; case PK_THREAD_STATE_SUSPENDED_RUNNABLE : break ; case PK_THREAD_STATE_SUSPENDED_BLOCKED : thread -> flags |= PK_THREAD_FLAG_TIMED_OUT ; thread -> state = PK_THREAD_STATE_SUSPENDED_RUNNABLE ; break ; default : PK_PANIC ( PK_THREAD_TIMEOUT_STATE ) ; } pk_critical_section_exit ( & ctx ) ; }
Generic thread timeout
This routine is called as a timer callback either because a sleeping thread
has timed out or a thread pending on a semaphore has timed out.
Generic thread timeout This routine is called as a timer callback either because a sleeping thread has timed out or a thread pending on a semaphore has timed out .