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(); }
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; }
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; }
void FreeGlobalPools() { // Release the allocated memory for this thread. TThreadGlobalPools* globalPools= static_cast<TThreadGlobalPools*>(OS_GetTLSValue(PoolIndex)); if (!globalPools) return; delete globalPools; }
TParseContextPointer& GetGlobalParseContext() { // // Minimal error checking for speed // TThreadParseContext *lpParseContext = static_cast<TThreadParseContext *>(OS_GetTLSValue(GlobalParseContextIndex)); return lpParseContext->lpGlobalParseContext; }
void InitializeGlobalPools() { TThreadGlobalPools* globalPools= static_cast<TThreadGlobalPools*>(OS_GetTLSValue(PoolIndex)); if (globalPools) return; TThreadGlobalPools* threadData = new TThreadGlobalPools(); threadData->globalPoolAllocator = 0; OS_SetTLSValue(PoolIndex, threadData); }
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; }
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; } }
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; }
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; }
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; }
void SetGlobalPoolAllocatorPtr(TPoolAllocator* poolAllocator) { TThreadGlobalPools* threadData = static_cast<TThreadGlobalPools*>(OS_GetTLSValue(PoolIndex)); threadData->globalPoolAllocator = poolAllocator; }
TPoolAllocator& GetGlobalPoolAllocator() { TThreadGlobalPools* threadData = static_cast<TThreadGlobalPools*>(OS_GetTLSValue(PoolIndex)); return *threadData->globalPoolAllocator; }
void SetThreadPoolAllocator(TPoolAllocator& poolAllocator) { TThreadMemoryPools* threadData = static_cast<TThreadMemoryPools*>(OS_GetTLSValue(PoolIndex)); threadData->threadPoolAllocator = &poolAllocator; }
TPoolAllocator& GetThreadPoolAllocator() { TThreadMemoryPools* threadData = static_cast<TThreadMemoryPools*>(OS_GetTLSValue(PoolIndex)); return *threadData->threadPoolAllocator; }