Example #1
0
static bool InitThread()
{
	if (s_ThreadInitialized == OS_INVALID_TLS_INDEX)
	{
		assert(0 && "InitThread(): Process hasn't been initalised.");
		return false;
	}

	// already initialized?
	if (OS_GetTLSValue(s_ThreadInitialized) != 0)
		return true;
	
	// initialize per-thread data
	InitializeGlobalPools();
	
	if (!InitializeGlobalParseContext())
		return false;
	
	if (!OS_SetTLSValue(s_ThreadInitialized, (void *)1))
	{
		assert(0 && "InitThread(): Unable to set init flag.");
		return false;
	}
	return true;
}
Example #2
0
void InitializeGlobalPools()
{
   TThreadGlobalPools* globalPools= static_cast<TThreadGlobalPools*>(OS_GetTLSValue(PoolIndex));    
   if (globalPools)
      return;

	void* poolMem, *threadPoolMem;
	TPoolAllocator *globalPoolAllocator;
	TThreadGlobalPools* threadData;
	
	if (_allocate) {
		poolMem = _allocate(sizeof(TPoolAllocator), _user_data);
		threadPoolMem = _allocate(sizeof(TThreadGlobalPools), _user_data);
		globalPoolAllocator = new (poolMem) TPoolAllocator(true);
		threadData = new (threadPoolMem) TThreadGlobalPools();
	} else {
		globalPoolAllocator = new TPoolAllocator(true);
		threadData = new TThreadGlobalPools();
	}

	threadData->globalPoolAllocator = globalPoolAllocator;

	OS_SetTLSValue(PoolIndex, threadData);     
	globalPoolAllocator->push();
}
Example #3
0
bool InitThread()
{
	//
    // This function is re-entrant
	//
    if (ThreadInitializeIndex == OS_INVALID_TLS_INDEX) {
		assert(0 && "InitThread(): Process hasn't been initalised.");
        return false;
	}

    if (OS_GetTLSValue(ThreadInitializeIndex) != 0)
        return true;

	InitializeGlobalPools();

	if (!InitializeGlobalParseContext())
        return false;

    if (!OS_SetTLSValue(ThreadInitializeIndex, (void *)1)) {
		assert(0 && "InitThread(): Unable to set init flag.");
        return false;
	}

    return true;
}
Example #4
0
void InitializeGlobalPools()
{
    TThreadGlobalPools* globalPools= static_cast<TThreadGlobalPools*>(OS_GetTLSValue(PoolIndex));    
    if (globalPools)
        return;

    TThreadGlobalPools* threadData = new TThreadGlobalPools();
    threadData->globalPoolAllocator = 0;

    OS_SetTLSValue(PoolIndex, threadData);
}
Example #5
0
static bool DetachThread()
{
	if (s_ThreadInitialized == OS_INVALID_TLS_INDEX)
		return true;
	if (OS_GetTLSValue(s_ThreadInitialized) == 0)
		return true;
	
	bool success = true;
	if (!OS_SetTLSValue(s_ThreadInitialized, (void *)0))
	{
		assert(0 && "DetachThread(): Unable to clear init flag.");
		success = false;
	}
	
	FreeGlobalPools();
	
	if (!FreeParseContext())
		success = false;
	
	return success;
}
Example #6
0
bool DetachThread()
{
    bool success = true;

    if (ThreadInitializeIndex == OS_INVALID_TLS_INDEX)
        return true;

	//
	// Function is re-entrant and this thread may not have been initalised.
	//
    if (OS_GetTLSValue(ThreadInitializeIndex) != 0) {
        if (!OS_SetTLSValue(ThreadInitializeIndex, (void *)0)) {
			assert(0 && "DetachThread(): Unable to clear init flag.");
            success = false;
		}

		FreeGlobalPools();

	}

    return success;
}
Example #7
0
bool InitializeGlobalParseContext()
{
    if (GlobalParseContextIndex == OS_INVALID_TLS_INDEX) {
        assert(0 && "InitializeGlobalParseContext(): Parse Context index not initalised");
        return false;
    }

    TThreadParseContext *lpParseContext = static_cast<TThreadParseContext *>(OS_GetTLSValue(GlobalParseContextIndex));
    if (lpParseContext != 0) {
        assert(0 && "InitializeParseContextIndex(): Parse Context already initalised");
        return false;
    }

    TThreadParseContext *lpThreadData = new TThreadParseContext();
    if (lpThreadData == 0) {
        assert(0 && "InitializeGlobalParseContext(): Unable to create thread parse context");
        return false;
    }

    lpThreadData->lpGlobalParseContext = 0;
    OS_SetTLSValue(GlobalParseContextIndex, lpThreadData);

    return true;
}