src/ppe/pk/kernel/pk_thread_core.c
/// Sleep a thread for an interval relative to the current time.
///
/// \param interval A time interval relative to the current timebase.
///
/// Threads can use this API to sleep for a time relative to the current
/// timebase.  The absolute timeout is \c pk_timebase_get() + \a interval.
///
///  Sleeping threads are not scheduled, although they maintain their
/// priorities.  This differs from thread suspension, where the suspended
/// thread relinquishes its priority.  When the sleep timer times out the
/// thread becomes runnable again, and will run as soon as it becomes the
/// highest-priority mapped runnable thread.
///
/// Sleeping threads may also be later suspended. In this case the Sleep timer
/// continues to run, and if it times out before the thread is resumed the
/// thread will be immediately runnable when it is resumed.
///
/// See the PK specification for a full discussion of how PK handles
/// scheduling events at absolute times "in the past". Briefly stated, if the
/// \a interval is 0 or is so small that the absolute time becomes a "past"
/// time before the Sleep is actually scheduled, the thread will Sleep for the
/// briefest possible period supported by the hardware.
///
/// Return values other than PK_OK (0) are errors; see \ref pk_errors
///
/// \retval 0 Successful completion.
///
/// \retval -PK_ILLEGAL_CONTEXT_THREAD The API was not called from a thread 
/// context.
Sleep a thread for an interval relative to the current time.
\param interval A time interval relative to the current timebase.

Threads can use this API to sleep for a time relative to the current
timebase.  The absolute timeout is \c pk_timebase_get() + \a interval.

Sleeping threads are not scheduled, although they maintain their
priorities.  This differs from thread suspension, where the suspended
thread relinquishes its priority.  When the sleep timer times out the
thread becomes runnable again, and will run as soon as it becomes the
highest-priority mapped runnable thread.

Sleeping threads may also be later suspended. In this case the Sleep timer
continues to run, and if it times out before the thread is resumed the
thread will be immediately runnable when it is resumed.

See the PK specification for a full discussion of how PK handles
scheduling events at absolute times "in the past". Briefly stated, if the
\a interval is 0 or is so small that the absolute time becomes a "past"
time before the Sleep is actually scheduled, the thread will Sleep for the
briefest possible period supported by the hardware.

Return values other than PK_OK (0) are errors; see \ref pk_errors

\retval 0 Successful completion.

\retval -PK_ILLEGAL_CONTEXT_THREAD The API was not called from a thread
context.
Sleep a thread for an interval relative to the current time . \ param interval A time interval relative to the current timebase . Threads can use this API to sleep for a time relative to the current timebase . The absolute timeout is \ c pk_timebase_get () + \ a interval . Sleeping threads are not scheduled although they maintain their priorities . This differs from thread suspension where the suspended thread relinquishes its priority . When the sleep timer times out the thread becomes runnable again and will run as soon as it becomes the highest - priority mapped runnable thread . Sleeping threads may also be later suspended . In this case the Sleep timer continues to run and if it times out before the thread is resumed the thread will be immediately runnable when it is resumed . See the PK specification for a full discussion of how PK handles scheduling events at absolute times " in the past " . Briefly stated if the \ a interval is 0 or is so small that the absolute time becomes a " past " time before the Sleep is actually scheduled the thread will Sleep for the briefest possible period supported by the hardware . Return values other than PK_OK ( 0 ) are errors ; see \ ref pk_errors \ retval 0 Successful completion . \ retval - PK_ILLEGAL_CONTEXT_THREAD The API was not called from a thread context .
int
pk_sleep(PkInterval interval) 
{
    PkTimebase  time;
    PkMachineContext ctx;
    PkThread *current;
    if (PK_ERROR_CHECK_API) {
        PK_ERROR_UNLESS_THREAD_CONTEXT();
    }
    time = pk_timebase_get() + PK_INTERVAL_SCALE(interval);
    pk_critical_section_enter(&ctx);
    current = (PkThread *)__pk_current_thread;
    current->timer.timeout = time;
    __pk_timer_schedule(&(current->timer));
    current->flags |= PK_THREAD_FLAG_TIMER_PEND;
    PK_KERN_TRACE("THREAD_SLEEP(%d)", current->priority);
    __pk_thread_queue_delete(&__pk_run_queue, current->priority);
    __pk_schedule();
    current->flags &= ~(PK_THREAD_FLAG_TIMER_PEND | PK_THREAD_FLAG_TIMED_OUT);
    pk_critical_section_exit(&ctx);
    return PK_OK;
}
int pk_sleep ( PkInterval interval ) { PkTimebase time ; PkMachineContext ctx ; PkThread * current ; if ( PK_ERROR_CHECK_API ) { PK_ERROR_UNLESS_THREAD_CONTEXT ( ) ; } time = pk_timebase_get ( ) + PK_INTERVAL_SCALE ( interval ) ; pk_critical_section_enter ( & ctx ) ; current = ( PkThread * ) __pk_current_thread ; current -> timer . timeout = time ; __pk_timer_schedule ( & ( current -> timer ) ) ; current -> flags |= PK_THREAD_FLAG_TIMER_PEND ; PK_KERN_TRACE ( " " , current -> priority ) ; __pk_thread_queue_delete ( & __pk_run_queue , current -> priority ) ; __pk_schedule ( ) ; current -> flags &= ~ ( PK_THREAD_FLAG_TIMER_PEND | PK_THREAD_FLAG_TIMED_OUT ) ; pk_critical_section_exit ( & ctx ) ; return PK_OK ; }
Sleep a thread for an interval relative to the current time.
Sleep a thread for an interval relative to the current time .