MCPcopy Create free account
hub / github.com/ElementsProject/elements / new_arena

Method new_arena

src/support/lockedpool.cpp:348–375  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

346}
347
348bool LockedPool::new_arena(size_t size, size_t align)
349{
350 bool locked;
351 // If this is the first arena, handle this specially: Cap the upper size
352 // by the process limit. This makes sure that the first arena will at least
353 // be locked. An exception to this is if the process limit is 0:
354 // in this case no memory can be locked at all so we'll skip past this logic.
355 if (arenas.empty()) {
356 size_t limit = allocator->GetLimit();
357 if (limit > 0) {
358 size = std::min(size, limit);
359 }
360 }
361 void *addr = allocator->AllocateLocked(size, &locked);
362 if (!addr) {
363 return false;
364 }
365 if (locked) {
366 cumulative_bytes_locked += size;
367 } else if (lf_cb) { // Call the locking-failed callback if locking failed
368 if (!lf_cb()) { // If the callback returns false, free the memory and fail, otherwise consider the user warned and proceed.
369 allocator->FreeLocked(addr, size);
370 return false;
371 }
372 }
373 arenas.emplace_back(allocator.get(), addr, size, align);
374 return true;
375}
376
377LockedPool::LockedPageArena::LockedPageArena(LockedPageAllocator *allocator_in, void *base_in, size_t size_in, size_t align_in):
378 Arena(base_in, size_in, align_in), base(base_in), size(size_in), allocator(allocator_in)

Callers

nothing calls this directly

Calls 6

emplace_backMethod · 0.80
emptyMethod · 0.45
GetLimitMethod · 0.45
AllocateLockedMethod · 0.45
FreeLockedMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected