Exemplo n.º 1
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();
}
Exemplo n.º 2
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;
}
Exemplo n.º 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;
}
Exemplo n.º 4
0
void FreeGlobalPools()
{
    // Release the allocated memory for this thread.
    TThreadGlobalPools* globalPools= static_cast<TThreadGlobalPools*>(OS_GetTLSValue(PoolIndex));    
    if (!globalPools)
        return;
 
    delete globalPools;
}
Exemplo n.º 5
0
TParseContextPointer& GetGlobalParseContext()
{
    //
    // Minimal error checking for speed
    //

    TThreadParseContext *lpParseContext = static_cast<TThreadParseContext *>(OS_GetTLSValue(GlobalParseContextIndex));

    return lpParseContext->lpGlobalParseContext;
}
Exemplo n.º 6
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);
}
Exemplo n.º 7
0
bool FreeParseContext()
{
    if (GlobalParseContextIndex == OS_INVALID_TLS_INDEX) {
        assert(0 && "FreeParseContext(): Parse Context index not initalised");
        return false;
    }

    TThreadParseContext *lpParseContext = static_cast<TThreadParseContext *>(OS_GetTLSValue(GlobalParseContextIndex));
    if (lpParseContext)
        delete lpParseContext;

    return true;
}
Exemplo n.º 8
0
void FreeGlobalPools()
{
   // Release the allocated memory for this thread.
   TThreadGlobalPools* globalPools= static_cast<TThreadGlobalPools*>(OS_GetTLSValue(PoolIndex));    
   if (!globalPools)
      return;

	GlobalPoolAllocator.popAll();
	if (_delete) {
	   _delete(&GlobalPoolAllocator, _user_data);
	   _delete(globalPools, _user_data);
	} else {
		delete &GlobalPoolAllocator;
		delete globalPools;
	}
}
Exemplo n.º 9
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;
}
Exemplo n.º 10
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;
}
Exemplo n.º 11
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;
}
Exemplo n.º 12
0
void SetGlobalPoolAllocatorPtr(TPoolAllocator* poolAllocator)
{
    TThreadGlobalPools* threadData = static_cast<TThreadGlobalPools*>(OS_GetTLSValue(PoolIndex));

    threadData->globalPoolAllocator = poolAllocator;
}
Exemplo n.º 13
0
TPoolAllocator& GetGlobalPoolAllocator()
{
    TThreadGlobalPools* threadData = static_cast<TThreadGlobalPools*>(OS_GetTLSValue(PoolIndex));

    return *threadData->globalPoolAllocator;
}
Exemplo n.º 14
0
void SetThreadPoolAllocator(TPoolAllocator& poolAllocator)
{
    TThreadMemoryPools* threadData = static_cast<TThreadMemoryPools*>(OS_GetTLSValue(PoolIndex));

    threadData->threadPoolAllocator = &poolAllocator;
}
Exemplo n.º 15
0
TPoolAllocator& GetThreadPoolAllocator()
{
    TThreadMemoryPools* threadData = static_cast<TThreadMemoryPools*>(OS_GetTLSValue(PoolIndex));

    return *threadData->threadPoolAllocator;
}