| 863 | } |
| 864 | |
| 865 | static 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 | |
| 883 | enum EDefrag { |
| 884 | MEM_DEFRAG, |
no test coverage detected