src/ppe/pk/kernel/pk_thread_core.c
/// Suspend a thread
///
/// Any active thread can be suspended.  A suspended thread 1) remains active
/// but will not be scheduled; 2) relinquishes its priority assignment,
/// allowing another thread to be resumed at the suspended thread's priority;
/// and 3) disassociates from any semaphore mutual exclusion it may have been
/// participating in.
///
/// If a sleeping thread is suspended, the sleep timer remains active but a
/// timeout of the timer simply marks the thread as runnable, but does not
/// resume the thread.  
///
/// If a thread blocked on a semaphore is suspended, the thread no longer
/// participates in the semaphore mutual exclusion. If the thread is later
/// resumed it will attempt to acquire the semaphore again the next time it
/// runs (unless it was blocked with a timeout and the timeout has expired).
///
/// If a thread blocked on a semaphore with timeout is suspended, the
/// semaphore timeout timer continues to run. If the timer times out while the
/// thread is suspended the thread is simply marked runnable. If the thread is
/// later resumed, the suspended call of \c pk_semaphore_pend() will return the
/// timeout code -PK_SEMAPHORE_PEND_TIMED_OUT.
///
/// Return values other than PK_OK (0) are errors; see \ref pk_errors
///
/// \retval 0 Successful completion, including calls on a \a thread that is
/// already suspended.
///
/// \retval -PK_INVALID_THREAD_AT_SUSPEND1 The \a thread is a null (0) pointer
/// 
/// \retval -PK_INVALID_THREAD_AT_SUSPEND2 The \a thread is not active, 
/// i.e. has completed or been deleted.
Suspend a thread
Any active thread can be suspended.  A suspended thread 1) remains active
but will not be scheduled; 2) relinquishes its priority assignment,
allowing another thread to be resumed at the suspended thread's priority;
and 3) disassociates from any semaphore mutual exclusion it may have been
participating in.

If a sleeping thread is suspended, the sleep timer remains active but a
timeout of the timer simply marks the thread as runnable, but does not
resume the thread.

If a thread blocked on a semaphore is suspended, the thread no longer
participates in the semaphore mutual exclusion. If the thread is later
resumed it will attempt to acquire the semaphore again the next time it
runs (unless it was blocked with a timeout and the timeout has expired).

If a thread blocked on a semaphore with timeout is suspended, the
semaphore timeout timer continues to run. If the timer times out while the
thread is suspended the thread is simply marked runnable. If the thread is
later resumed, the suspended call of \c pk_semaphore_pend() will return the
timeout code -PK_SEMAPHORE_PEND_TIMED_OUT.

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

\retval 0 Successful completion, including calls on a \a thread that is
already suspended.

\retval -PK_INVALID_THREAD_AT_SUSPEND1 The \a thread is a null (0) pointer

\retval -PK_INVALID_THREAD_AT_SUSPEND2 The \a thread is not active,
i.e. has completed or been deleted.
Suspend a thread Any active thread can be suspended . A suspended thread 1 ) remains active but will not be scheduled ; 2 ) relinquishes its priority assignment allowing another thread to be resumed at the suspended thread ' s priority ; and 3 ) disassociates from any semaphore mutual exclusion it may have been participating in . If a sleeping thread is suspended the sleep timer remains active but a timeout of the timer simply marks the thread as runnable but does not resume the thread . If a thread blocked on a semaphore is suspended the thread no longer participates in the semaphore mutual exclusion . If the thread is later resumed it will attempt to acquire the semaphore again the next time it runs ( unless it was blocked with a timeout and the timeout has expired ) . If a thread blocked on a semaphore with timeout is suspended the semaphore timeout timer continues to run . If the timer times out while the thread is suspended the thread is simply marked runnable . If the thread is later resumed the suspended call of \ c pk_semaphore_pend () will return the timeout code - PK_SEMAPHORE_PEND_TIMED_OUT . Return values other than PK_OK ( 0 ) are errors ; see \ ref pk_errors \ retval 0 Successful completion including calls on a \ a thread that is already suspended . \ retval - PK_INVALID_THREAD_AT_SUSPEND1 The \ a thread is a null ( 0 ) pointer \ retval - PK_INVALID_THREAD_AT_SUSPEND2 The \ a thread is not active i . e . has completed or been deleted .
int
pk_thread_suspend(PkThread *thread)
{
    PkMachineContext ctx;
    if (PK_ERROR_CHECK_API) {
        PK_ERROR_IF((thread == 0), PK_INVALID_THREAD_AT_SUSPEND1);
    }
    pk_critical_section_enter(&ctx);
    if (PK_ERROR_CHECK_API) {
        PK_ERROR_IF_CRITICAL(!__pk_thread_is_active(thread),
                              PK_INVALID_THREAD_AT_SUSPEND2,
                              &ctx);
    }
    if (__pk_thread_is_mapped(thread)) {
        PK_KERN_TRACE("THREAD_SUSPENDED(%d)", thread->priority);
        __pk_thread_unmap(thread);
        __pk_schedule();
    }
    pk_critical_section_exit(&ctx);
    return PK_OK;
}
int pk_thread_suspend ( PkThread * thread ) { PkMachineContext ctx ; if ( PK_ERROR_CHECK_API ) { PK_ERROR_IF ( ( thread == 0 ) , PK_INVALID_THREAD_AT_SUSPEND1 ) ; } pk_critical_section_enter ( & ctx ) ; if ( PK_ERROR_CHECK_API ) { PK_ERROR_IF_CRITICAL ( ! __pk_thread_is_active ( thread ) , PK_INVALID_THREAD_AT_SUSPEND2 , & ctx ) ; } if ( __pk_thread_is_mapped ( thread ) ) { PK_KERN_TRACE ( " " , thread -> priority ) ; __pk_thread_unmap ( thread ) ; __pk_schedule ( ) ; } pk_critical_section_exit ( & ctx ) ; return PK_OK ; }
Suspend a thread
Any active thread can be suspended.
Suspend a thread Any active thread can be suspended .