third_party/virtualbox/src/VBox/Runtime/common/misc/thread.cpp
/**
 * Allocates a per thread data structure and initializes the basic fields.
 *
 * @returns Pointer to per thread data structure.
 *          This is reference once.
 * @returns NULL on failure.
 * @param   enmType     The thread type.
 * @param   fFlags      The thread flags.
 * @param   fIntFlags   The internal thread flags.
 * @param   pszName     Pointer to the thread name.
 */
Allocates a per thread data structure and initializes the basic fields.
@returns Pointer to per thread data structure.
This is reference once.
@returns NULL on failure.
@param   enmType     The thread type.
@param   fFlags      The thread flags.
@param   fIntFlags   The internal thread flags.
@param   pszName     Pointer to the thread name.
Allocates a per thread data structure and initializes the basic fields . @returns Pointer to per thread data structure . This is reference once . @returns NULL on failure . @param enmType The thread type . @param fFlags The thread flags . @param fIntFlags The internal thread flags . @param pszName Pointer to the thread name .
PRTTHREADINT rtThreadAlloc(RTTHREADTYPE enmType, unsigned fFlags, uint32_t fIntFlags, const char *pszName)
{
    PRTTHREADINT pThread = (PRTTHREADINT)RTMemAllocZ(sizeof(RTTHREADINT));
    if (pThread)
    {
        size_t cchName;
        int rc;
        pThread->Core.Key   = (void*)NIL_RTTHREAD;
        pThread->u32Magic   = RTTHREADINT_MAGIC;
        cchName = strlen(pszName);
        if (cchName >= RTTHREAD_NAME_LEN)
            cchName = RTTHREAD_NAME_LEN - 1;
        memcpy(pThread->szName, pszName, cchName);
        pThread->szName[cchName] = '\0';
        pThread->cRefs           = 2 + !!(fFlags & RTTHREADFLAGS_WAITABLE); 
        pThread->rc              = VERR_PROCESS_RUNNING; 
        pThread->enmType         = enmType;
        pThread->fFlags          = fFlags;
        pThread->fIntFlags       = fIntFlags;
        pThread->enmState        = RTTHREADSTATE_INITIALIZING;
        pThread->fReallySleeping = false;
#ifdef IN_RING3
        rtLockValidatorInitPerThread(&pThread->LockValidator);
#endif
#ifdef RT_WITH_ICONV_CACHE
        rtStrIconvCacheInit(pThread);
#endif
        rc = RTSemEventMultiCreate(&pThread->EventUser);
        if (RT_SUCCESS(rc))
        {
            rc = RTSemEventMultiCreate(&pThread->EventTerminated);
            if (RT_SUCCESS(rc))
                return pThread;
            RTSemEventMultiDestroy(pThread->EventUser);
        }
        RTMemFree(pThread);
    }
    return NULL;
}
PRTTHREADINT rtThreadAlloc ( RTTHREADTYPE enmType , unsigned fFlags , uint32_t fIntFlags , const char * pszName ) { PRTTHREADINT pThread = ( PRTTHREADINT ) RTMemAllocZ ( sizeof ( RTTHREADINT ) ) ; if ( pThread ) { size_t cchName ; int rc ; pThread -> Core . Key = ( void * ) NIL_RTTHREAD ; pThread -> u32Magic = RTTHREADINT_MAGIC ; cchName = strlen ( pszName ) ; if ( cchName >= RTTHREAD_NAME_LEN ) cchName = RTTHREAD_NAME_LEN - 1 ; memcpy ( pThread -> szName , pszName , cchName ) ; pThread -> szName [ cchName ] = ' \0 ' ; pThread -> cRefs = 2 + ! ! ( fFlags & RTTHREADFLAGS_WAITABLE ) ; pThread -> rc = VERR_PROCESS_RUNNING ; pThread -> enmType = enmType ; pThread -> fFlags = fFlags ; pThread -> fIntFlags = fIntFlags ; pThread -> enmState = RTTHREADSTATE_INITIALIZING ; pThread -> fReallySleeping = false ; #ifdef IN_RING3 rtLockValidatorInitPerThread ( & pThread -> LockValidator ) ; #endif #ifdef RT_WITH_ICONV_CACHE rtStrIconvCacheInit ( pThread ) ; #endif rc = RTSemEventMultiCreate ( & pThread -> EventUser ) ; if ( RT_SUCCESS ( rc ) ) { rc = RTSemEventMultiCreate ( & pThread -> EventTerminated ) ; if ( RT_SUCCESS ( rc ) ) return pThread ; RTSemEventMultiDestroy ( pThread -> EventUser ) ; } RTMemFree ( pThread ) ; } return NULL ; }
Allocates a per thread data structure and initializes the basic fields.
Allocates a per thread data structure and initializes the basic fields .
/* And extra reference if waitable. */ /** @todo get a better error code! */