예제 #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();
}
예제 #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;
}
예제 #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;
}
예제 #4
0
파일: PoolAlloc.cpp 프로젝트: Afreeca/qt
void FreeGlobalPools()
{
    // Release the allocated memory for this thread.
    TThreadGlobalPools* globalPools= static_cast<TThreadGlobalPools*>(OS_GetTLSValue(PoolIndex));    
    if (!globalPools)
        return;
 
    delete globalPools;
}
예제 #5
0
TParseContextPointer& GetGlobalParseContext()
{
    //
    // Minimal error checking for speed
    //

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

    return lpParseContext->lpGlobalParseContext;
}
예제 #6
0
파일: PoolAlloc.cpp 프로젝트: Afreeca/qt
void InitializeGlobalPools()
{
    TThreadGlobalPools* globalPools= static_cast<TThreadGlobalPools*>(OS_GetTLSValue(PoolIndex));    
    if (globalPools)
        return;

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

    OS_SetTLSValue(PoolIndex, threadData);
}
예제 #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;
}
예제 #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;
	}
}
예제 #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;
}
예제 #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;
}
예제 #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;
}
예제 #12
0
void SetGlobalPoolAllocatorPtr(TPoolAllocator* poolAllocator)
{
    TThreadGlobalPools* threadData = static_cast<TThreadGlobalPools*>(OS_GetTLSValue(PoolIndex));

    threadData->globalPoolAllocator = poolAllocator;
}
예제 #13
0
TPoolAllocator& GetGlobalPoolAllocator()
{
    TThreadGlobalPools* threadData = static_cast<TThreadGlobalPools*>(OS_GetTLSValue(PoolIndex));

    return *threadData->globalPoolAllocator;
}
예제 #14
0
void SetThreadPoolAllocator(TPoolAllocator& poolAllocator)
{
    TThreadMemoryPools* threadData = static_cast<TThreadMemoryPools*>(OS_GetTLSValue(PoolIndex));

    threadData->threadPoolAllocator = &poolAllocator;
}
예제 #15
0
TPoolAllocator& GetThreadPoolAllocator()
{
    TThreadMemoryPools* threadData = static_cast<TThreadMemoryPools*>(OS_GetTLSValue(PoolIndex));

    return *threadData->threadPoolAllocator;
}