MCPcopy Create free account
hub / github.com/async-profiler/async-profiler / alloc

Method alloc

src/linearAllocator.cpp:35–52  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

33}
34
35void* LinearAllocator::alloc(size_t size) {
36 Chunk* chunk = _tail;
37
38 do {
39 // Fast path: bump a pointer with CAS
40 for (size_t offs = chunk->offs; offs + size <= _chunk_size; offs = chunk->offs) {
41 if (__sync_bool_compare_and_swap(&chunk->offs, offs, offs + size)) {
42 if (_chunk_size / 2 - offs < size) {
43 // Stepped over a middle of the chunk - it's time to prepare a new one
44 reserveChunk(chunk);
45 }
46 return (char*)chunk + offs;
47 }
48 }
49 } while ((chunk = getNextChunk(chunk)) != NULL);
50
51 return NULL;
52}
53
54Chunk* LinearAllocator::allocateChunk(Chunk* current) {
55 Chunk* chunk = (Chunk*)OS::safeAlloc(_chunk_size);

Callers 1

storeCallTraceMethod · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected