Autonomy Software C++ 24.5.1
Welcome to the Autonomy Software repository of the Mars Rover Design Team (MRDT) at Missouri University of Science and Technology (Missouri S&T)! API reference contains the source code and other resources for the development of the autonomy software for our Mars rover. The Autonomy Software project aims to compete in the University Rover Challenge (URC) by demonstrating advanced autonomous capabilities and robust navigation algorithms.
Loading...
Searching...
No Matches
duckdb::BlockAllocatorThreadLocalState Class Reference
Collaboration diagram for duckdb::BlockAllocatorThreadLocalState:

Public Member Functions

 BlockAllocatorThreadLocalState (const BlockAllocator &block_allocator_p)
void TryInitialize (const BlockAllocator &block_allocator_p)
data_ptr_t Allocate ()
void Free (const data_ptr_t pointer)
void Clear ()

Private Member Functions

void Initialize (const BlockAllocator &block_allocator_p)
data_ptr_t TryAllocateFromLocal ()

Static Private Member Functions

static bool TryGetBatch (vector< uint32_t > &local, BlockQueue &global)

Private Attributes

hugeint_t cached_uuid
optional_ptr< const BlockAllocator > block_allocator
vector< uint32_t > untouched
vector< uint32_t > touched

Static Private Attributes

static constexpr idx_t BATCH_SIZE = 128
static constexpr idx_t FREE_THRESHOLD = BATCH_SIZE * 2

Constructor & Destructor Documentation

◆ BlockAllocatorThreadLocalState()

duckdb::BlockAllocatorThreadLocalState::BlockAllocatorThreadLocalState ( const BlockAllocator & block_allocator_p)
inlineexplicit
386458 {
386459 Initialize(block_allocator_p);
386460 }

◆ ~BlockAllocatorThreadLocalState()

duckdb::BlockAllocatorThreadLocalState::~BlockAllocatorThreadLocalState ( )
inline
386461 {
386462 Clear();
386463 }

Member Function Documentation

◆ TryInitialize()

void duckdb::BlockAllocatorThreadLocalState::TryInitialize ( const BlockAllocator & block_allocator_p)
inline
386466 {
386467 // Local state can be invalidated if DB closes but thread stays alive
386468 if (cached_uuid != block_allocator_p.uuid) {
386469 Initialize(block_allocator_p);
386470 }
386471 }

◆ Allocate()

data_ptr_t duckdb::BlockAllocatorThreadLocalState::Allocate ( )
inline
386473 {
386474 auto pointer = TryAllocateFromLocal();
386475 if (pointer) {
386476 return pointer;
386477 }
386478
386479 // We have run out of local blocks
386480 if (TryGetBatch(touched, *block_allocator->touched) || TryGetBatch(untouched, *block_allocator->untouched)) {
386481 // We have refilled local blocks
386482 pointer = TryAllocateFromLocal();
386483 D_ASSERT(pointer);
386484 return pointer;
386485 }
386486
386487 // We have also run out of global blocks, use fallback allocator
386488 return block_allocator->allocator.AllocateData(block_allocator->block_size);
386489 }

◆ Free()

void duckdb::BlockAllocatorThreadLocalState::Free ( const data_ptr_t pointer)
inline
386491 {
386492 touched.push_back(block_allocator->GetBlockID(pointer));
386493 if (touched.size() < FREE_THRESHOLD) {
386494 return;
386495 }
386496
386497 // Upon reaching the threshold, we return a local batch to global
386498 std::sort(touched.begin(), touched.end());
386499 block_allocator->touched->q.enqueue_bulk(touched.end() - BATCH_SIZE, BATCH_SIZE);
386500 touched.resize(touched.size() - BATCH_SIZE);
386501 }

◆ Clear()

void duckdb::BlockAllocatorThreadLocalState::Clear ( )
inline
386503 {
386504 // Return all local blocks back to global
386505 if (!touched.empty()) {
386506 block_allocator->touched->q.enqueue_bulk(touched.begin(), touched.size());
386507 touched.clear();
386508 }
386509 if (!untouched.empty()) {
386510 block_allocator->untouched->q.enqueue_bulk(untouched.begin(), untouched.size());
386511 untouched.clear();
386512 }
386513 }

◆ Initialize()

void duckdb::BlockAllocatorThreadLocalState::Initialize ( const BlockAllocator & block_allocator_p)
inlineprivate
386516 {
386517 cached_uuid = block_allocator_p.uuid;
386518 block_allocator = block_allocator_p;
386519 untouched.clear();
386520 touched.clear();
386521 untouched.reserve(BATCH_SIZE);
386522 touched.reserve(FREE_THRESHOLD);
386523 }

◆ TryAllocateFromLocal()

data_ptr_t duckdb::BlockAllocatorThreadLocalState::TryAllocateFromLocal ( )
inlineprivate
386525 {
386526 if (!touched.empty()) {
386527 const auto pointer = block_allocator->GetPointer(touched.back());
386528 touched.pop_back();
386529 return pointer;
386530 }
386531 if (!untouched.empty()) {
386532 const auto pointer = block_allocator->GetPointer(untouched.back());
386533 untouched.pop_back();
386534 OnFirstAllocation(pointer, block_allocator->block_size);
386535 return pointer;
386536 }
386537 return nullptr;
386538 }

◆ TryGetBatch()

bool duckdb::BlockAllocatorThreadLocalState::TryGetBatch ( vector< uint32_t > & local,
BlockQueue & global )
inlinestaticprivate
386540 {
386541 D_ASSERT(local.empty());
386542 local.resize(BATCH_SIZE);
386543 const auto size = global.q.try_dequeue_bulk(local.begin(), BATCH_SIZE);
386544 local.resize(size);
386545 std::sort(local.begin(), local.end());
386546 return !local.empty();
386547 }
GOpaque< Size > size(const GMat &src)

The documentation for this class was generated from the following file: