MCPcopy Create free account
hub / github.com/catboost/catboost / LFAllocFromCurrentChunk

Function LFAllocFromCurrentChunk

library/cpp/lfalloc/lf_allocX64.h:865–881  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

863}
864
865static Y_FORCE_INLINE void* LFAllocFromCurrentChunk(int nSizeIdx, int blockSize, int count) {
866 char* volatile* pFreeArray = &globalCurrentPtr[nSizeIdx];
867 while (char* newBlock = *pFreeArray) {
868 char* nextFree = newBlock + blockSize * count;
869
870 // check if there is space in chunk
871 char* globalEndPtr = ALLOC_START + ((newBlock - ALLOC_START) & ~((uintptr_t)N_CHUNK_SIZE - 1)) + N_CHUNK_SIZE;
872 if (nextFree >= globalEndPtr) {
873 if (nextFree > globalEndPtr)
874 break;
875 nextFree = nullptr; // it was last block in chunk
876 }
877 if (DoCas(pFreeArray, nextFree, newBlock) == newBlock)
878 return newBlock;
879 }
880 return nullptr;
881}
882
883enum EDefrag {
884 MEM_DEFRAG,

Callers 3

SlowLFAllocFunction · 0.85
LFAllocNoCacheFunction · 0.85
LFAllocNoCacheMultipleFunction · 0.85

Calls 1

DoCasFunction · 0.70

Tested by

no test coverage detected