src/ppe/pk/kernel/pk_thread_core.c
/// Resume a suspended thread
///
/// \param thread The thread to resume
///
/// PK only allows one thread at a time to run at a given priority, and
/// implements the notion of a thread \e claiming a priority.  A suspended
/// thread claims a priority when it is mapped by a call of
/// pk_thread_resume().  This API will succeed only if no other active thread
/// is currently mapped at the priority assigned to the thread.  PK provides
/// the pk_thread_at_priority() API which allows an application-level
/// scheduler to correctly manage multiple threads running at the same
/// priority.  
///
/// If the thread was sleeping while suspended it remains asleep. However if
/// the sleep timer timed out while the thread was suspended it will be
/// resumed runnable.
/// 
/// If the thread was blocked on a semaphore when it was suspended, then when
/// the thread is resumed it will attempt to reacquire the semaphore.
/// However, if the thread was blocked on a semaphore with timeout while
/// suspended and the timeout interval has passed, the thread will be resumed
/// runnable and see that the semaphore pend timed out.
///
/// It is not an error to call pk_thread_resume() on a mapped
/// thread.  However it is an error to call pk_thread_resume() on a completed
/// or deleted thread.
/// 
/// 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 mapped.
///
/// \retval -PK_INVALID_THREAD_AT_RESUME1 The \a thread is a null (0) pointer.
/// 
/// \retval -PK_INVALID_THREAD_AT_RESUME2 The \a thread is not active, 
/// i.e. has completed or been deleted.
/// 
/// \retval -PK_PRIORITY_IN_USE_AT_RESUME Another thread is already mapped at 
/// the priority of the \a thread.
Resume a suspended thread
\param thread The thread to resume

PK only allows one thread at a time to run at a given priority, and
implements the notion of a thread \e claiming a priority.  A suspended
thread claims a priority when it is mapped by a call of
pk_thread_resume().  This API will succeed only if no other active thread
is currently mapped at the priority assigned to the thread.  PK provides
the pk_thread_at_priority() API which allows an application-level
scheduler to correctly manage multiple threads running at the same
priority.

If the thread was sleeping while suspended it remains asleep. However if
the sleep timer timed out while the thread was suspended it will be
resumed runnable.

If the thread was blocked on a semaphore when it was suspended, then when
the thread is resumed it will attempt to reacquire the semaphore.
However, if the thread was blocked on a semaphore with timeout while
suspended and the timeout interval has passed, the thread will be resumed
runnable and see that the semaphore pend timed out.

It is not an error to call pk_thread_resume() on a mapped
thread.  However it is an error to call pk_thread_resume() on a completed
or deleted thread.

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 mapped.

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

\retval -PK_INVALID_THREAD_AT_RESUME2 The \a thread is not active,
i.e. has completed or been deleted.

\retval -PK_PRIORITY_IN_USE_AT_RESUME Another thread is already mapped at
the priority of the \a thread.
Resume a suspended thread \ param thread The thread to resume PK only allows one thread at a time to run at a given priority and implements the notion of a thread \ e claiming a priority . A suspended thread claims a priority when it is mapped by a call of pk_thread_resume () . This API will succeed only if no other active thread is currently mapped at the priority assigned to the thread . PK provides the pk_thread_at_priority () API which allows an application - level scheduler to correctly manage multiple threads running at the same priority . If the thread was sleeping while suspended it remains asleep . However if the sleep timer timed out while the thread was suspended it will be resumed runnable . If the thread was blocked on a semaphore when it was suspended then when the thread is resumed it will attempt to reacquire the semaphore . However if the thread was blocked on a semaphore with timeout while suspended and the timeout interval has passed the thread will be resumed runnable and see that the semaphore pend timed out . It is not an error to call pk_thread_resume () on a mapped thread . However it is an error to call pk_thread_resume () on a completed or deleted thread . 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 mapped . \ retval - PK_INVALID_THREAD_AT_RESUME1 The \ a thread is a null ( 0 ) pointer . \ retval - PK_INVALID_THREAD_AT_RESUME2 The \ a thread is not active i . e . has completed or been deleted . \ retval - PK_PRIORITY_IN_USE_AT_RESUME Another thread is already mapped at the priority of the \ a thread .
int
pk_thread_resume(PkThread *thread)
{
    PkMachineContext ctx;
    if (PK_ERROR_CHECK_API) {
        PK_ERROR_IF(thread == 0, PK_INVALID_THREAD_AT_RESUME1);
    }
    pk_critical_section_enter(&ctx);
    if (PK_ERROR_CHECK_API) {
        PK_ERROR_IF_CRITICAL(!__pk_thread_is_active(thread),
                              PK_INVALID_THREAD_AT_RESUME2,
                              &ctx);
    }
    if (!__pk_thread_is_mapped(thread)) {
        if (PK_ERROR_CHECK_API) {
            PK_ERROR_IF_CRITICAL(__pk_priority_map[thread->priority] != 0,
                                  PK_PRIORITY_IN_USE_AT_RESUME,
                                  &ctx);
        }
        __pk_thread_map(thread);
        __pk_schedule();
    }
    pk_critical_section_exit(&ctx);
    return PK_OK;
}
int pk_thread_resume ( PkThread * thread ) { PkMachineContext ctx ; if ( PK_ERROR_CHECK_API ) { PK_ERROR_IF ( thread == 0 , PK_INVALID_THREAD_AT_RESUME1 ) ; } pk_critical_section_enter ( & ctx ) ; if ( PK_ERROR_CHECK_API ) { PK_ERROR_IF_CRITICAL ( ! __pk_thread_is_active ( thread ) , PK_INVALID_THREAD_AT_RESUME2 , & ctx ) ; } if ( ! __pk_thread_is_mapped ( thread ) ) { if ( PK_ERROR_CHECK_API ) { PK_ERROR_IF_CRITICAL ( __pk_priority_map [ thread -> priority ] != 0 , PK_PRIORITY_IN_USE_AT_RESUME , & ctx ) ; } __pk_thread_map ( thread ) ; __pk_schedule ( ) ; } pk_critical_section_exit ( & ctx ) ; return PK_OK ; }
Resume a suspended thread
\param thread The thread to resume
Resume a suspended thread \ param thread The thread to resume