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_moodycamel::ConcurrentQueue< T, Traits >::ImplicitProducer Struct Reference
Inheritance diagram for duckdb_moodycamel::ConcurrentQueue< T, Traits >::ImplicitProducer:
Collaboration diagram for duckdb_moodycamel::ConcurrentQueue< T, Traits >::ImplicitProducer:

Classes

struct  BlockIndexEntry
struct  BlockIndexHeader

Public Member Functions

 ImplicitProducer (ConcurrentQueue *parent_)
template<AllocationMode allocMode, typename U>
bool enqueue (U &&element)
template<typename U>
bool dequeue (U &element)
template<AllocationMode allocMode, typename It>
bool enqueue_bulk (It itemFirst, size_t count)
template<typename It>
size_t dequeue_bulk (It &itemFirst, size_t max)
Public Member Functions inherited from duckdb_moodycamel::ConcurrentQueue< T, Traits >::ProducerBase
 ProducerBase (ConcurrentQueue *parent_, bool isExplicit_)
template<typename U>
bool dequeue (U &element)
template<typename It>
size_t dequeue_bulk (It &itemFirst, size_t max)
ProducerBase * next_prod () const
size_t size_approx () const
index_t getTail () const

Private Member Functions

template<AllocationMode allocMode>
bool insert_block_index_entry (BlockIndexEntry *&idxEntry, index_t blockStartIndex)
void rewind_block_index_tail ()
BlockIndexEntry * get_block_index_entry_for_index (index_t index) const
size_t get_block_index_index_for_index (index_t index, BlockIndexHeader *&localBlockIndex) const
bool new_block_index ()

Private Attributes

size_t nextBlockIndexCapacity
std::atomic< BlockIndexHeader * > blockIndex

Static Private Attributes

static const index_t INVALID_BLOCK_BASE = 1

Additional Inherited Members

Public Attributes inherited from duckdb_moodycamel::ConcurrentQueue< T, Traits >::ProducerBase
bool isExplicit
ConcurrentQueue * parent
Public Attributes inherited from duckdb_moodycamel::details::ConcurrentQueueProducerTypelessBase
ConcurrentQueueProducerTypelessBase * next
std::atomic< bool > inactive
ProducerToken * token
Protected Attributes inherited from duckdb_moodycamel::ConcurrentQueue< T, Traits >::ProducerBase
std::atomic< index_t > tailIndex
std::atomic< index_t > headIndex
std::atomic< index_t > dequeueOptimisticCount
std::atomic< index_t > dequeueOvercommit
Block * tailBlock

Constructor & Destructor Documentation

◆ ImplicitProducer()

template<typename T, typename Traits = ConcurrentQueueDefaultTraits>
duckdb_moodycamel::ConcurrentQueue< T, Traits >::ImplicitProducer::ImplicitProducer ( ConcurrentQueue * parent_)
inline
333174 :
333175 ProducerBase(parent_, false),
333176 nextBlockIndexCapacity(IMPLICIT_INITIAL_INDEX_SIZE),
333177 blockIndex(nullptr)
333178 {
333179 new_block_index();
333180 }
Definition duckdb.cpp:331497

◆ ~ImplicitProducer()

template<typename T, typename Traits = ConcurrentQueueDefaultTraits>
duckdb_moodycamel::ConcurrentQueue< T, Traits >::ImplicitProducer::~ImplicitProducer ( )
inline
333183 {
333184 // Note that since we're in the destructor we can assume that all enqueue/dequeue operations
333185 // completed already; this means that all undequeued elements are placed contiguously across
333186 // contiguous blocks, and that only the first and last remaining blocks can be only partially
333187 // empty (all other remaining blocks must be completely full).
333188
333189#ifdef MOODYCAMEL_CPP11_THREAD_LOCAL_SUPPORTED
333190 // Unregister ourselves for thread termination notification
333191 if (!this->inactive.load(std::memory_order_relaxed)) {
333193 }
333194#endif
333195
333196 // Destroy all remaining elements!
333197 auto tail = this->tailIndex.load(std::memory_order_relaxed);
333198 auto index = this->headIndex.load(std::memory_order_relaxed);
333199 Block* block = nullptr;
333201 bool forceFreeLastBlock = index != tail; // If we enter the loop, then the last (tail) block will not be freed
333202 while (index != tail) {
333203 if ((index & static_cast<index_t>(BLOCK_SIZE - 1)) == 0 || block == nullptr) {
333204 if (block != nullptr) {
333205 // Free the old block
333206 this->parent->add_block_to_free_list(block);
333207 }
333208
333209 block = get_block_index_entry_for_index(index)->value.load(std::memory_order_relaxed);
333210 }
333211
333212 ((*block)[index])->~T();
333213 ++index;
333214 }
333215 // Even if the queue is empty, there's still one block that's not on the free list
333216 // (unless the head index reached the end of it, in which case the tail will be poised
333217 // to create a new block).
333218 if (this->tailBlock != nullptr && (forceFreeLastBlock || (tail & static_cast<index_t>(BLOCK_SIZE - 1)) != 0)) {
333219 this->parent->add_block_to_free_list(this->tailBlock);
333220 }
333221
333222 // Destroy block index
333223 auto localBlockIndex = blockIndex.load(std::memory_order_relaxed);
333224 if (localBlockIndex != nullptr) {
333225 for (size_t i = 0; i != localBlockIndex->capacity; ++i) {
333226 localBlockIndex->index[i]->~BlockIndexEntry();
333227 }
333228 do {
333229 auto prev = localBlockIndex->prev;
333230 localBlockIndex->~BlockIndexHeader();
333233 } while (localBlockIndex != nullptr);
333234 }
333235 }
#define assert(x)
Definition duckdb.cpp:486071

Member Function Documentation

◆ enqueue()

template<typename T, typename Traits = ConcurrentQueueDefaultTraits>
template<AllocationMode allocMode, typename U>
bool duckdb_moodycamel::ConcurrentQueue< T, Traits >::ImplicitProducer::enqueue ( U && element)
inline
333239 {
333240 index_t currentTailIndex = this->tailIndex.load(std::memory_order_relaxed);
333242 if ((currentTailIndex & static_cast<index_t>(BLOCK_SIZE - 1)) == 0) {
333243 // We reached the end of a block, start a new one
333244 auto head = this->headIndex.load(std::memory_order_relaxed);
333247 return false;
333248 }
333249#ifdef MCDBGQ_NOLOCKFREE_IMPLICITPRODBLOCKINDEX
333251#endif
333252 // Find out where we'll be inserting this block in the block index
333254 if (!insert_block_index_entry<allocMode>(idxEntry, currentTailIndex)) {
333255 return false;
333256 }
333257
333258 // Get ahold of a new block
333259 auto newBlock = this->parent->ConcurrentQueue::template requisition_block<allocMode>();
333260 if (newBlock == nullptr) {
333261 rewind_block_index_tail();
333262 idxEntry->value.store(nullptr, std::memory_order_relaxed);
333263 return false;
333264 }
333265#ifdef MCDBGQ_TRACKMEM
333266 newBlock->owner = this;
333267#endif
333268 newBlock->ConcurrentQueue::Block::template reset_empty<implicit_context>();
333269
333270 if (!MOODYCAMEL_NOEXCEPT_CTOR(T, U, new ((T*)nullptr) T(std::forward<U>(element)))) {
333271 // May throw, try to insert now before we publish the fact that we have this new block
333273 new ((*newBlock)[currentTailIndex]) T(std::forward<U>(element));
333274 }
333275 MOODYCAMEL_CATCH (...) {
333276 rewind_block_index_tail();
333277 idxEntry->value.store(nullptr, std::memory_order_relaxed);
333278 this->parent->add_block_to_free_list(newBlock);
333280 }
333281 }
333282
333283 // Insert the new block into the index
333285
333286 this->tailBlock = newBlock;
333287
333288 if (!MOODYCAMEL_NOEXCEPT_CTOR(T, U, new ((T*)nullptr) T(std::forward<U>(element)))) {
333289 this->tailIndex.store(newTailIndex, std::memory_order_release);
333290 return true;
333291 }
333292 }
333293
333294 // Enqueue
333295 new ((*this->tailBlock)[currentTailIndex]) T(std::forward<U>(element));
333296
333297 this->tailIndex.store(newTailIndex, std::memory_order_release);
333298 return true;
333299 }

◆ dequeue()

template<typename T, typename Traits = ConcurrentQueueDefaultTraits>
template<typename U>
bool duckdb_moodycamel::ConcurrentQueue< T, Traits >::ImplicitProducer::dequeue ( U & element)
inline
333303 {
333304 // See ExplicitProducer::dequeue for rationale and explanation
333305 index_t tail = this->tailIndex.load(std::memory_order_relaxed);
333306 index_t overcommit = this->dequeueOvercommit.load(std::memory_order_relaxed);
333307 if (details::circular_less_than<index_t>(this->dequeueOptimisticCount.load(std::memory_order_relaxed) - overcommit, tail)) {
333309
333310 index_t myDequeueCount = this->dequeueOptimisticCount.fetch_add(1, std::memory_order_relaxed);
333311 tail = this->tailIndex.load(std::memory_order_acquire);
333313 index_t index = this->headIndex.fetch_add(1, std::memory_order_acq_rel);
333314
333315 // Determine which block the element is in
333316 auto entry = get_block_index_entry_for_index(index);
333317
333318 // Dequeue
333319 auto block = entry->value.load(std::memory_order_relaxed);
333320 auto& el = *((*block)[index]);
333321
333323#ifdef MCDBGQ_NOLOCKFREE_IMPLICITPRODBLOCKINDEX
333324 // Note: Acquiring the mutex with every dequeue instead of only when a block
333325 // is released is very sub-optimal, but it is, after all, purely debug code.
333327#endif
333328 struct Guard {
333329 Block* block;
333330 index_t index;
333333
333334 ~Guard()
333335 {
333336 (*block)[index]->~T();
333337 if (block->ConcurrentQueue::Block::template set_empty<implicit_context>(index)) {
333338 entry->value.store(nullptr, std::memory_order_relaxed);
333339 parent->add_block_to_free_list(block);
333340 }
333341 }
333342 } guard = { block, index, entry, this->parent };
333343
333344 element = std::move(el); // NOLINT
333345 }
333346 else {
333347 element = std::move(el); // NOLINT
333348 el.~T(); // NOLINT
333349
333350 if (block->ConcurrentQueue::Block::template set_empty<implicit_context>(index)) {
333351 {
333352#ifdef MCDBGQ_NOLOCKFREE_IMPLICITPRODBLOCKINDEX
333354#endif
333355 // Add the block back into the global free pool (and remove from block index)
333356 entry->value.store(nullptr, std::memory_order_relaxed);
333357 }
333358 this->parent->add_block_to_free_list(block); // releases the above store
333359 }
333360 }
333361
333362 return true;
333363 }
333364 else {
333365 this->dequeueOvercommit.fetch_add(1, std::memory_order_release);
333366 }
333367 }
333368
333369 return false;
333370 }

◆ enqueue_bulk()

template<typename T, typename Traits = ConcurrentQueueDefaultTraits>
template<AllocationMode allocMode, typename It>
bool duckdb_moodycamel::ConcurrentQueue< T, Traits >::ImplicitProducer::enqueue_bulk ( It itemFirst,
size_t count )
inline
333374 {
333375 // First, we need to make sure we have enough room to enqueue all of the elements;
333376 // this means pre-allocating blocks and putting them in the block index (but only if
333377 // all the allocations succeeded).
333378
333379 // Note that the tailBlock we start off with may not be owned by us any more;
333380 // this happens if it was filled up exactly to the top (setting tailIndex to
333381 // the first index of the next block which is not yet allocated), then dequeued
333382 // completely (putting it on the free list) before we enqueue again.
333383
333384 index_t startTailIndex = this->tailIndex.load(std::memory_order_relaxed);
333385 auto startBlock = this->tailBlock;
333386 Block* firstAllocatedBlock = nullptr;
333387 auto endBlock = this->tailBlock;
333388
333389 // Figure out how many blocks we'll need to allocate, and do so
333390 size_t blockBaseDiff = ((startTailIndex + count - 1) & ~static_cast<index_t>(BLOCK_SIZE - 1)) - ((startTailIndex - 1) & ~static_cast<index_t>(BLOCK_SIZE - 1));
333391 index_t currentTailIndex = (startTailIndex - 1) & ~static_cast<index_t>(BLOCK_SIZE - 1);
333392 if (blockBaseDiff > 0) {
333393#ifdef MCDBGQ_NOLOCKFREE_IMPLICITPRODBLOCKINDEX
333395#endif
333396 do {
333397 blockBaseDiff -= static_cast<index_t>(BLOCK_SIZE);
333398 currentTailIndex += static_cast<index_t>(BLOCK_SIZE);
333399
333400 // Find out where we'll be inserting this block in the block index
333401 BlockIndexEntry* idxEntry = nullptr; // initialization here unnecessary but compiler can't always tell
333402 Block* newBlock;
333403 bool indexInserted = false;
333404 auto head = this->headIndex.load(std::memory_order_relaxed);
333407 if (full || !(indexInserted = insert_block_index_entry<allocMode>(idxEntry, currentTailIndex)) || (newBlock = this->parent->ConcurrentQueue::template requisition_block<allocMode>()) == nullptr) {
333408 // Index allocation or block allocation failed; revert any other allocations
333409 // and index insertions done so far for this operation
333410 if (indexInserted) {
333411 rewind_block_index_tail();
333412 idxEntry->value.store(nullptr, std::memory_order_relaxed);
333413 }
333414 currentTailIndex = (startTailIndex - 1) & ~static_cast<index_t>(BLOCK_SIZE - 1);
333415 for (auto block = firstAllocatedBlock; block != nullptr; block = block->next) {
333416 currentTailIndex += static_cast<index_t>(BLOCK_SIZE);
333417 idxEntry = get_block_index_entry_for_index(currentTailIndex);
333418 idxEntry->value.store(nullptr, std::memory_order_relaxed);
333419 rewind_block_index_tail();
333420 }
333421 this->parent->add_blocks_to_free_list(firstAllocatedBlock);
333422 this->tailBlock = startBlock;
333423
333424 return false;
333425 }
333426
333427#ifdef MCDBGQ_TRACKMEM
333428 newBlock->owner = this;
333429#endif
333430 newBlock->ConcurrentQueue::Block::template reset_empty<implicit_context>();
333431 newBlock->next = nullptr;
333432
333433 // Insert the new block into the index
333435
333436 // Store the chain of blocks so that we can undo if later allocations fail,
333437 // and so that we can find the blocks when we do the actual enqueueing
333438 if ((startTailIndex & static_cast<index_t>(BLOCK_SIZE - 1)) != 0 || firstAllocatedBlock != nullptr) {
333439 assert(this->tailBlock != nullptr);
333440 this->tailBlock->next = newBlock;
333441 }
333442 this->tailBlock = newBlock;
333443 endBlock = newBlock;
333445 } while (blockBaseDiff > 0);
333446 }
333447
333448 // Enqueue, one block at a time
333449 index_t newTailIndex = startTailIndex + static_cast<index_t>(count);
333451 this->tailBlock = startBlock;
333452 assert((startTailIndex & static_cast<index_t>(BLOCK_SIZE - 1)) != 0 || firstAllocatedBlock != nullptr || count == 0);
333453 if ((startTailIndex & static_cast<index_t>(BLOCK_SIZE - 1)) == 0 && firstAllocatedBlock != nullptr) {
333454 this->tailBlock = firstAllocatedBlock;
333455 }
333456 while (true) {
333460 }
333461 if (MOODYCAMEL_NOEXCEPT_CTOR(T, decltype(*itemFirst), new ((T*)nullptr) T(details::deref_noexcept(itemFirst)))) {
333462 while (currentTailIndex != stopIndex) {
333463 new ((*this->tailBlock)[currentTailIndex++]) T(*itemFirst++);
333464 }
333465 }
333466 else {
333468 while (currentTailIndex != stopIndex) {
333469 new ((*this->tailBlock)[currentTailIndex]) T(details::nomove_if<(bool)!MOODYCAMEL_NOEXCEPT_CTOR(T, decltype(*itemFirst), new ((T*)nullptr) T(details::deref_noexcept(itemFirst)))>::eval(*itemFirst));
333471 ++itemFirst;
333472 }
333473 }
333474 MOODYCAMEL_CATCH (...) {
333476 auto lastBlockEnqueued = this->tailBlock;
333477
333479 auto block = startBlock;
333480 if ((startTailIndex & static_cast<index_t>(BLOCK_SIZE - 1)) == 0) {
333482 }
333484 while (true) {
333488 }
333489 while (currentTailIndex != stopIndex) {
333490 (*block)[currentTailIndex++]->~T();
333491 }
333492 if (block == lastBlockEnqueued) {
333493 break;
333494 }
333495 block = block->next;
333496 }
333497 }
333498
333499 currentTailIndex = (startTailIndex - 1) & ~static_cast<index_t>(BLOCK_SIZE - 1);
333500 for (auto block = firstAllocatedBlock; block != nullptr; block = block->next) {
333501 currentTailIndex += static_cast<index_t>(BLOCK_SIZE);
333502 auto idxEntry = get_block_index_entry_for_index(currentTailIndex);
333503 idxEntry->value.store(nullptr, std::memory_order_relaxed);
333504 rewind_block_index_tail();
333505 }
333506 this->parent->add_blocks_to_free_list(firstAllocatedBlock);
333507 this->tailBlock = startBlock;
333509 }
333510 }
333511
333512 if (this->tailBlock == endBlock) {
333514 break;
333515 }
333516 this->tailBlock = this->tailBlock->next;
333517 }
333518 this->tailIndex.store(newTailIndex, std::memory_order_release);
333519 return true;
333520 }

◆ dequeue_bulk()

template<typename T, typename Traits = ConcurrentQueueDefaultTraits>
template<typename It>
size_t duckdb_moodycamel::ConcurrentQueue< T, Traits >::ImplicitProducer::dequeue_bulk ( It & itemFirst,
size_t max )
inline
333524 {
333525 auto tail = this->tailIndex.load(std::memory_order_relaxed);
333526 auto overcommit = this->dequeueOvercommit.load(std::memory_order_relaxed);
333527 auto desiredCount = static_cast<size_t>(tail - (this->dequeueOptimisticCount.load(std::memory_order_relaxed) - overcommit));
333531
333532 auto myDequeueCount = this->dequeueOptimisticCount.fetch_add(desiredCount, std::memory_order_relaxed);
333533
333534 tail = this->tailIndex.load(std::memory_order_acquire);
333535 auto actualCount = static_cast<size_t>(tail - (myDequeueCount - overcommit));
333538 if (actualCount < desiredCount) {
333539 this->dequeueOvercommit.fetch_add(desiredCount - actualCount, std::memory_order_release);
333540 }
333541
333542 // Get the first index. Note that since there's guaranteed to be at least actualCount elements, this
333543 // will never exceed tail.
333544 auto firstIndex = this->headIndex.fetch_add(actualCount, std::memory_order_acq_rel);
333545
333546 // Iterate the blocks and dequeue
333547 auto index = firstIndex;
333549 auto indexIndex = get_block_index_index_for_index(index, localBlockIndex);
333550 do {
333551 auto blockStartIndex = index;
333552 auto endIndex = (index & ~static_cast<index_t>(BLOCK_SIZE - 1)) + static_cast<index_t>(BLOCK_SIZE);
333554
333555 auto entry = localBlockIndex->index[indexIndex];
333556 auto block = entry->value.load(std::memory_order_relaxed);
333558 while (index != endIndex) {
333559 auto& el = *((*block)[index]);
333560 *itemFirst++ = std::move(el);
333561 el.~T();
333562 ++index;
333563 }
333564 }
333565 else {
333567 while (index != endIndex) {
333568 auto& el = *((*block)[index]);
333569 *itemFirst = std::move(el);
333570 ++itemFirst;
333571 el.~T();
333572 ++index;
333573 }
333574 }
333575 MOODYCAMEL_CATCH (...) {
333576 do {
333577 entry = localBlockIndex->index[indexIndex];
333578 block = entry->value.load(std::memory_order_relaxed);
333579 while (index != endIndex) {
333580 (*block)[index++]->~T();
333581 }
333582
333583 if (block->ConcurrentQueue::Block::template set_many_empty<implicit_context>(blockStartIndex, static_cast<size_t>(endIndex - blockStartIndex))) {
333584#ifdef MCDBGQ_NOLOCKFREE_IMPLICITPRODBLOCKINDEX
333586#endif
333587 entry->value.store(nullptr, std::memory_order_relaxed);
333588 this->parent->add_block_to_free_list(block);
333589 }
333590 indexIndex = (indexIndex + 1) & (localBlockIndex->capacity - 1);
333591
333595 } while (index != firstIndex + actualCount);
333596
333598 }
333599 }
333600 if (block->ConcurrentQueue::Block::template set_many_empty<implicit_context>(blockStartIndex, static_cast<size_t>(endIndex - blockStartIndex))) {
333601 {
333602#ifdef MCDBGQ_NOLOCKFREE_IMPLICITPRODBLOCKINDEX
333604#endif
333605 // Note that the set_many_empty above did a release, meaning that anybody who acquires the block
333606 // we're about to free can use it safely since our writes (and reads!) will have happened-before then.
333607 entry->value.store(nullptr, std::memory_order_relaxed);
333608 }
333609 this->parent->add_block_to_free_list(block); // releases the above store
333610 }
333611 indexIndex = (indexIndex + 1) & (localBlockIndex->capacity - 1);
333612 } while (index != firstIndex + actualCount);
333613
333614 return actualCount;
333615 }
333616 else {
333617 this->dequeueOvercommit.fetch_add(desiredCount, std::memory_order_release);
333618 }
333619 }
333620
333621 return 0;
333622 }

◆ insert_block_index_entry()

template<typename T, typename Traits = ConcurrentQueueDefaultTraits>
template<AllocationMode allocMode>
bool duckdb_moodycamel::ConcurrentQueue< T, Traits >::ImplicitProducer::insert_block_index_entry ( BlockIndexEntry *& idxEntry,
index_t blockStartIndex )
inlineprivate
333645 {
333646 auto localBlockIndex = blockIndex.load(std::memory_order_relaxed); // We're the only writer thread, relaxed is OK
333647 if (localBlockIndex == nullptr) {
333648 return false; // this can happen if new_block_index failed in the constructor
333649 }
333650 auto newTail = (localBlockIndex->tail.load(std::memory_order_relaxed) + 1) & (localBlockIndex->capacity - 1);
333651 idxEntry = localBlockIndex->index[newTail];
333652 if (idxEntry->key.load(std::memory_order_relaxed) == INVALID_BLOCK_BASE ||
333653 idxEntry->value.load(std::memory_order_relaxed) == nullptr) {
333654
333657 return true;
333658 }
333659
333660 // No room in the old block index, try to allocate another one!
333662 return false;
333663 }
333664 else if (!new_block_index()) {
333665 return false;
333666 }
333667 localBlockIndex = blockIndex.load(std::memory_order_relaxed);
333668 newTail = (localBlockIndex->tail.load(std::memory_order_relaxed) + 1) & (localBlockIndex->capacity - 1);
333669 idxEntry = localBlockIndex->index[newTail];
333670 assert(idxEntry->key.load(std::memory_order_relaxed) == INVALID_BLOCK_BASE);
333673 return true;
333674 }

◆ rewind_block_index_tail()

template<typename T, typename Traits = ConcurrentQueueDefaultTraits>
void duckdb_moodycamel::ConcurrentQueue< T, Traits >::ImplicitProducer::rewind_block_index_tail ( )
inlineprivate
333677 {
333678 auto localBlockIndex = blockIndex.load(std::memory_order_relaxed);
333680 }

◆ get_block_index_entry_for_index()

template<typename T, typename Traits = ConcurrentQueueDefaultTraits>
BlockIndexEntry * duckdb_moodycamel::ConcurrentQueue< T, Traits >::ImplicitProducer::get_block_index_entry_for_index ( index_t index) const
inlineprivate
333683 {
333685 auto idx = get_block_index_index_for_index(index, localBlockIndex);
333686 return localBlockIndex->index[idx];
333687 }

◆ get_block_index_index_for_index()

template<typename T, typename Traits = ConcurrentQueueDefaultTraits>
size_t duckdb_moodycamel::ConcurrentQueue< T, Traits >::ImplicitProducer::get_block_index_index_for_index ( index_t index,
BlockIndexHeader *& localBlockIndex ) const
inlineprivate
333690 {
333691#ifdef MCDBGQ_NOLOCKFREE_IMPLICITPRODBLOCKINDEX
333693#endif
333695 localBlockIndex = blockIndex.load(std::memory_order_acquire);
333697 auto tailBase = localBlockIndex->index[tail]->key.load(std::memory_order_relaxed);
333698 assert(tailBase != INVALID_BLOCK_BASE);
333699 // Note: Must use division instead of shift because the index may wrap around, causing a negative
333700 // offset, whose negativity we want to preserve
333701 auto offset = static_cast<size_t>(static_cast<typename std::make_signed<index_t>::type>(index - tailBase) / static_cast<typename std::make_signed<index_t>::type>(BLOCK_SIZE));
333702 size_t idx = (tail + offset) & (localBlockIndex->capacity - 1);
333703 assert(localBlockIndex->index[idx]->key.load(std::memory_order_relaxed) == index && localBlockIndex->index[idx]->value.load(std::memory_order_relaxed) != nullptr);
333704 return idx;
333705 }

◆ new_block_index()

template<typename T, typename Traits = ConcurrentQueueDefaultTraits>
bool duckdb_moodycamel::ConcurrentQueue< T, Traits >::ImplicitProducer::new_block_index ( )
inlineprivate
333708 {
333709 auto prev = blockIndex.load(std::memory_order_relaxed);
333710 size_t prevCapacity = prev == nullptr ? 0 : prev->capacity;
333711 auto entryCount = prev == nullptr ? nextBlockIndexCapacity : prevCapacity;
333712 auto raw = static_cast<char*>((Traits::malloc)(
333713 sizeof(BlockIndexHeader) +
333715 std::alignment_of<BlockIndexEntry*>::value - 1 + sizeof(BlockIndexEntry*) * nextBlockIndexCapacity));
333716 if (raw == nullptr) {
333717 return false;
333718 }
333719
333720 auto header = new (raw) BlockIndexHeader;
333722 auto index = reinterpret_cast<BlockIndexEntry**>(details::align_for<BlockIndexEntry*>(reinterpret_cast<char*>(entries) + sizeof(BlockIndexEntry) * entryCount));
333723 if (prev != nullptr) {
333724 auto prevTail = prev->tail.load(std::memory_order_relaxed);
333725 auto prevPos = prevTail;
333726 size_t i = 0;
333727 do {
333728 prevPos = (prevPos + 1) & (prev->capacity - 1);
333729 index[i++] = prev->index[prevPos];
333730 } while (prevPos != prevTail);
333731 assert(i == prevCapacity);
333732 }
333733 for (size_t i = 0; i != entryCount; ++i) {
333734 new (entries + i) BlockIndexEntry;
333735 entries[i].key.store(INVALID_BLOCK_BASE, std::memory_order_relaxed);
333736 index[prevCapacity + i] = entries + i;
333737 }
333738 header->prev = prev;
333739 header->entries = entries;
333740 header->index = index;
333741 header->capacity = nextBlockIndexCapacity;
333742 header->tail.store((prevCapacity - 1) & (nextBlockIndexCapacity - 1), std::memory_order_relaxed);
333743
333744 blockIndex.store(header, std::memory_order_release);
333745
333746 nextBlockIndexCapacity <<= 1;
333747
333748 return true;
333749 }

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