third_party/virtualbox/src/VBox/Runtime/common/misc/thread.cpp
/**
 * Destroys the per thread data.
 *
 * @param   pThread     The thread to destroy.
 */
Destroys the per thread data.
@param   pThread     The thread to destroy.
Destroys the per thread data . @param pThread The thread to destroy .
static void rtThreadDestroy(PRTTHREADINT pThread)
{
    RTSEMEVENTMULTI hEvt1, hEvt2;
    if (ASMBitTest(&pThread->fIntFlags, RTTHREADINT_FLAG_IN_TREE_BIT))
    {
        ASMAtomicIncU32(&pThread->cRefs);
        rtThreadRemove(pThread);
        ASMAtomicDecU32(&pThread->cRefs);
    }
#ifdef IN_RING3
    rtLockValidatorSerializeDestructEnter();
    rtLockValidatorDeletePerThread(&pThread->LockValidator);
#endif
#ifdef RT_WITH_ICONV_CACHE
    rtStrIconvCacheDestroy(pThread);
#endif
    ASMAtomicXchgU32(&pThread->u32Magic, RTTHREADINT_MAGIC_DEAD);
    ASMAtomicWritePtr(&pThread->Core.Key, (void *)NIL_RTTHREAD);
    pThread->enmType         = RTTHREADTYPE_INVALID;
    hEvt1    = pThread->EventUser;
    pThread->EventUser       = NIL_RTSEMEVENTMULTI;
    hEvt2    = pThread->EventTerminated;
    pThread->EventTerminated = NIL_RTSEMEVENTMULTI;
#ifdef IN_RING3
    rtLockValidatorSerializeDestructLeave();
#endif
    RTSemEventMultiDestroy(hEvt1);
    if (hEvt2 != NIL_RTSEMEVENTMULTI)
        RTSemEventMultiDestroy(hEvt2);
    rtThreadNativeDestroy(pThread);
    RTMemFree(pThread);
}
static void rtThreadDestroy ( PRTTHREADINT pThread ) { RTSEMEVENTMULTI hEvt1 , hEvt2 ; if ( ASMBitTest ( & pThread -> fIntFlags , RTTHREADINT_FLAG_IN_TREE_BIT ) ) { ASMAtomicIncU32 ( & pThread -> cRefs ) ; rtThreadRemove ( pThread ) ; ASMAtomicDecU32 ( & pThread -> cRefs ) ; } #ifdef IN_RING3 rtLockValidatorSerializeDestructEnter ( ) ; rtLockValidatorDeletePerThread ( & pThread -> LockValidator ) ; #endif #ifdef RT_WITH_ICONV_CACHE rtStrIconvCacheDestroy ( pThread ) ; #endif ASMAtomicXchgU32 ( & pThread -> u32Magic , RTTHREADINT_MAGIC_DEAD ) ; ASMAtomicWritePtr ( & pThread -> Core . Key , ( void * ) NIL_RTTHREAD ) ; pThread -> enmType = RTTHREADTYPE_INVALID ; hEvt1 = pThread -> EventUser ; pThread -> EventUser = NIL_RTSEMEVENTMULTI ; hEvt2 = pThread -> EventTerminated ; pThread -> EventTerminated = NIL_RTSEMEVENTMULTI ; #ifdef IN_RING3 rtLockValidatorSerializeDestructLeave ( ) ; #endif RTSemEventMultiDestroy ( hEvt1 ) ; if ( hEvt2 != NIL_RTSEMEVENTMULTI ) RTSemEventMultiDestroy ( hEvt2 ) ; rtThreadNativeDestroy ( pThread ) ; RTMemFree ( pThread ) ; }
Destroys the per thread data.
Destroys the per thread data .
/*
     * Remove it from the tree and mark it as dead.
     *
     * Threads that has seen rtThreadTerminate and should already have been
     * removed from the tree. There is probably no thread that  should
     * require removing here. However, be careful making sure that cRefs
     * isn't 0 if we do or we'll blow up because the strict locking code
     * will be calling us back.
     */ /*
     * Invalidate the thread structure.
     */ /*
     * Destroy semaphore resources and free the bugger.
     */