src/ppe/pk/kernel/pk_thread_core.c
// This routine is only used locally. 
//
// Completion and deletion are pretty much the same thing.  Completion is
// simply self-deletion of the current thread (which is mapped by
// definition.) The complete/delete APIs have slightly different error
// conditions but are otherwise the same.
//
// Deleting a mapped thread first unmaps (suspends) the thread, which takes
// care of removing the thread from any semaphores it may be pending on.  Then
// any outstanding timer is also cancelled.
//
// If the current thread is being deleted we install the idle thread as
// __pk_current_thread, so scheduling is forced and no context is saved on
// the context switch.
//
// 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.
This routine is only used locally.
Completion and deletion are pretty much the same thing.  Completion is
simply self-deletion of the current thread (which is mapped by
definition.) The complete/delete APIs have slightly different error
conditions but are otherwise the same.

Deleting a mapped thread first unmaps (suspends) the thread, which takes
care of removing the thread from any semaphores it may be pending on.  Then
any outstanding timer is also cancelled.

If the current thread is being deleted we install the idle thread as
pk_current_thread, so scheduling is forced and no context is saved on
the context switch.

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.
This routine is only used locally . Completion and deletion are pretty much the same thing . Completion is simply self - deletion of the current thread ( which is mapped by definition . ) The complete / delete APIs have slightly different error conditions but are otherwise the same . Deleting a mapped thread first unmaps ( suspends ) the thread which takes care of removing the thread from any semaphores it may be pending on . Then any outstanding timer is also cancelled . If the current thread is being deleted we install the idle thread as pk_current_thread so scheduling is forced and no context is saved on the context switch . 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_delete(PkThread *thread, PkThreadState final_state)
{
    PkMachineContext ctx;
    int mapped;
    pk_critical_section_enter(&ctx);
    mapped = __pk_thread_is_mapped(thread);
    if (mapped) {
        __pk_thread_unmap(thread);
    }
    __pk_timer_cancel(&(thread->timer));
    thread->state = final_state;
    if (mapped) {
        if (PK_KERNEL_TRACE_ENABLE) {
            if (final_state == PK_THREAD_STATE_DELETED) {
                PK_KERN_TRACE("THREAD_DELETED(%d)", thread->priority);
            } else {
                PK_KERN_TRACE("THREAD_COMPLETED(%d)", thread->priority);
            }
        }                
        if (thread == __pk_current_thread) {
            __pk_current_thread = 0;
        }
        __pk_schedule();
    }
    pk_critical_section_exit(&ctx);
}
void __pk_thread_delete ( PkThread * thread , PkThreadState final_state ) { PkMachineContext ctx ; int mapped ; pk_critical_section_enter ( & ctx ) ; mapped = __pk_thread_is_mapped ( thread ) ; if ( mapped ) { __pk_thread_unmap ( thread ) ; } __pk_timer_cancel ( & ( thread -> timer ) ) ; thread -> state = final_state ; if ( mapped ) { if ( PK_KERNEL_TRACE_ENABLE ) { if ( final_state == PK_THREAD_STATE_DELETED ) { PK_KERN_TRACE ( " " , thread -> priority ) ; } else { PK_KERN_TRACE ( " " , thread -> priority ) ; } } if ( thread == __pk_current_thread ) { __pk_current_thread = 0 ; } __pk_schedule ( ) ; } pk_critical_section_exit ( & ctx ) ; }
This routine is only used locally.
This routine is only used locally .