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 > Class Template Reference
Collaboration diagram for duckdb_moodycamel::ConcurrentQueue< T, Traits >:

Classes

struct  FreeListNode
struct  FreeList
struct  Block
struct  ProducerBase
struct  ExplicitProducer
struct  ImplicitProducer
struct  ImplicitProducerKVP
struct  ImplicitProducerHash

Public Types

typedef ::duckdb_moodycamel::ProducerToken producer_token_t
typedef ::duckdb_moodycamel::ConsumerToken consumer_token_t
typedef Traits::index_t index_t
typedef Traits::size_t size_t

Public Member Functions

 ConcurrentQueue (size_t capacity=6 *BLOCK_SIZE)
 ConcurrentQueue (size_t minCapacity, size_t maxExplicitProducers, size_t maxImplicitProducers)
 ConcurrentQueue (ConcurrentQueue const &) MOODYCAMEL_DELETE_FUNCTION
ConcurrentQueue & operator= (ConcurrentQueue const &) MOODYCAMEL_DELETE_FUNCTION
 ConcurrentQueue (ConcurrentQueue &&other) MOODYCAMEL_NOEXCEPT
ConcurrentQueue & operator= (ConcurrentQueue &&other) MOODYCAMEL_NOEXCEPT
void swap (ConcurrentQueue &other) MOODYCAMEL_NOEXCEPT
bool enqueue (T const &item)
bool enqueue (T &&item)
bool enqueue (producer_token_t const &token, T const &item)
bool enqueue (producer_token_t const &token, T &&item)
template<typename It>
bool enqueue_bulk (It itemFirst, size_t count)
template<typename It>
bool enqueue_bulk (producer_token_t const &token, It itemFirst, size_t count)
bool try_enqueue (T const &item)
bool try_enqueue (T &&item)
bool try_enqueue (producer_token_t const &token, T const &item)
bool try_enqueue (producer_token_t const &token, T &&item)
template<typename It>
bool try_enqueue_bulk (It itemFirst, size_t count)
template<typename It>
bool try_enqueue_bulk (producer_token_t const &token, It itemFirst, size_t count)
template<typename U>
bool try_dequeue (U &item)
template<typename U>
bool try_dequeue_non_interleaved (U &item)
template<typename U>
bool try_dequeue (consumer_token_t &token, U &item)
template<typename It>
size_t try_dequeue_bulk (It itemFirst, size_t max)
template<typename It>
size_t try_dequeue_bulk (consumer_token_t &token, It itemFirst, size_t max)
template<typename U>
bool try_dequeue_from_producer (producer_token_t const &producer, U &item)
template<typename It>
size_t try_dequeue_bulk_from_producer (producer_token_t const &producer, It itemFirst, size_t max)
size_t size_approx () const
size_t size_producers_approx () const
size_t size_producer_approx (producer_token_t const &producer) const

Static Public Member Functions

static bool is_lock_free ()

Static Public Attributes

static const size_t BLOCK_SIZE = static_cast<size_t>(Traits::BLOCK_SIZE)
static const size_t EXPLICIT_BLOCK_EMPTY_COUNTER_THRESHOLD = static_cast<size_t>(Traits::EXPLICIT_BLOCK_EMPTY_COUNTER_THRESHOLD)
static const size_t EXPLICIT_INITIAL_INDEX_SIZE = static_cast<size_t>(Traits::EXPLICIT_INITIAL_INDEX_SIZE)
static const size_t IMPLICIT_INITIAL_INDEX_SIZE = static_cast<size_t>(Traits::IMPLICIT_INITIAL_INDEX_SIZE)
static const size_t INITIAL_IMPLICIT_PRODUCER_HASH_SIZE = static_cast<size_t>(Traits::INITIAL_IMPLICIT_PRODUCER_HASH_SIZE)
static const std::uint32_t EXPLICIT_CONSUMER_CONSUMPTION_QUOTA_BEFORE_ROTATE = static_cast<std::uint32_t>(Traits::EXPLICIT_CONSUMER_CONSUMPTION_QUOTA_BEFORE_ROTATE)
static const size_t MAX_SUBQUEUE_SIZE = (details::const_numeric_max<size_t>::value - static_cast<size_t>(Traits::MAX_SUBQUEUE_SIZE) < BLOCK_SIZE) ? details::const_numeric_max<size_t>::value : ((static_cast<size_t>(Traits::MAX_SUBQUEUE_SIZE) + (BLOCK_SIZE - 1)) / BLOCK_SIZE * BLOCK_SIZE)

Private Types

enum  AllocationMode { CanAlloc , CannotAlloc }
enum  InnerQueueContext { implicit_context = 0 , explicit_context = 1 }

Private Member Functions

ConcurrentQueue & swap_internal (ConcurrentQueue &other)
template<AllocationMode canAlloc, typename U>
bool inner_enqueue (producer_token_t const &token, U &&element)
template<AllocationMode canAlloc, typename U>
bool inner_enqueue (U &&element)
template<AllocationMode canAlloc, typename It>
bool inner_enqueue_bulk (producer_token_t const &token, It itemFirst, size_t count)
template<AllocationMode canAlloc, typename It>
bool inner_enqueue_bulk (It itemFirst, size_t count)
bool update_current_producer_after_rotation (consumer_token_t &token)
void populate_initial_block_list (size_t blockCount)
Block * try_get_block_from_initial_pool ()
void add_block_to_free_list (Block *block)
void add_blocks_to_free_list (Block *block)
Block * try_get_block_from_free_list ()
template<AllocationMode canAlloc>
Block * requisition_block ()
ProducerBase * recycle_or_create_producer (bool isExplicit)
ProducerBase * recycle_or_create_producer (bool isExplicit, bool &recycled)
ProducerBase * add_producer (ProducerBase *producer)
void reown_producers ()
void populate_initial_implicit_producer_hash ()
void swap_implicit_producer_hashes (ConcurrentQueue &other)
ImplicitProducer * get_or_add_implicit_producer ()

Static Private Member Functions

template<typename TAlign>
static void * aligned_malloc (size_t size)
template<typename TAlign>
static void aligned_free (void *ptr)
template<typename U>
static U * create_array (size_t count)
template<typename U>
static void destroy_array (U *p, size_t count)
template<typename U>
static U * create ()
template<typename U, typename A1>
static U * create (A1 &&a1)
template<typename U>
static void destroy (U *p)

Private Attributes

std::atomic< ProducerBase * > producerListTail
std::atomic< std::uint32_t > producerCount
std::atomic< size_t > initialBlockPoolIndex
Block * initialBlockPool
size_t initialBlockPoolSize
FreeList< Block > freeList
std::atomic< ImplicitProducerHash * > implicitProducerHash
std::atomic< size_t > implicitProducerHashCount
ImplicitProducerHash initialImplicitProducerHash
std::array< ImplicitProducerKVP, INITIAL_IMPLICIT_PRODUCER_HASH_SIZE > initialImplicitProducerHashEntries
std::atomic_flag implicitProducerHashResizeInProgress
std::atomic< std::uint32_t > nextExplicitConsumerId
std::atomic< std::uint32_t > globalExplicitConsumerOffset

Friends

struct ProducerToken
struct ConsumerToken
struct ExplicitProducer
struct ImplicitProducer
class ConcurrentQueueTests
template<typename XT, typename XTraits>
void duckdb_moodycamel::swap (typename ConcurrentQueue< XT, XTraits >::ImplicitProducerKVP &, typename ConcurrentQueue< XT, XTraits >::ImplicitProducerKVP &) MOODYCAMEL_NOEXCEPT

Member Enumeration Documentation

◆ AllocationMode

template<typename T, typename Traits = ConcurrentQueueDefaultTraits>
enum duckdb_moodycamel::ConcurrentQueue::AllocationMode
private
332105{ CanAlloc, CannotAlloc };

◆ InnerQueueContext

template<typename T, typename Traits = ConcurrentQueueDefaultTraits>
enum duckdb_moodycamel::ConcurrentQueue::InnerQueueContext
private
332303{ implicit_context = 0, explicit_context = 1 };

Constructor & Destructor Documentation

◆ ConcurrentQueue() [1/3]

template<typename T, typename Traits = ConcurrentQueueDefaultTraits>
duckdb_moodycamel::ConcurrentQueue< T, Traits >::ConcurrentQueue ( size_t capacity = 6 * BLOCK_SIZE)
inlineexplicit
331543 : producerListTail(nullptr),
331544 producerCount(0),
331545 initialBlockPoolIndex(0),
331546 nextExplicitConsumerId(0),
331547 globalExplicitConsumerOffset(0)
331548 {
331549 implicitProducerHashResizeInProgress.clear(std::memory_order_relaxed);
331550 populate_initial_implicit_producer_hash();
331551 populate_initial_block_list(capacity / BLOCK_SIZE + ((capacity & (BLOCK_SIZE - 1)) == 0 ? 0 : 1));
331552
331553#ifdef MOODYCAMEL_QUEUE_INTERNAL_DEBUG
331554 // Track all the producers using a fully-resolved typed list for
331555 // each kind; this makes it possible to debug them starting from
331556 // the root queue object (otherwise wacky casts are needed that
331557 // don't compile in the debugger's expression evaluator).
331560#endif
331561 }
Definition duckdb.cpp:331497

◆ ConcurrentQueue() [2/3]

template<typename T, typename Traits = ConcurrentQueueDefaultTraits>
duckdb_moodycamel::ConcurrentQueue< T, Traits >::ConcurrentQueue ( size_t minCapacity,
size_t maxExplicitProducers,
size_t maxImplicitProducers )
inline
331567 : producerListTail(nullptr),
331568 producerCount(0),
331569 initialBlockPoolIndex(0),
331570 nextExplicitConsumerId(0),
331571 globalExplicitConsumerOffset(0)
331572 {
331573 implicitProducerHashResizeInProgress.clear(std::memory_order_relaxed);
331574 populate_initial_implicit_producer_hash();
331575 size_t blocks = (((minCapacity + BLOCK_SIZE - 1) / BLOCK_SIZE) - 1) * (maxExplicitProducers + 1) + 2 * (maxExplicitProducers + maxImplicitProducers);
331576 populate_initial_block_list(blocks);
331577
331578#ifdef MOODYCAMEL_QUEUE_INTERNAL_DEBUG
331581#endif
331582 }

◆ ~ConcurrentQueue()

template<typename T, typename Traits = ConcurrentQueueDefaultTraits>
duckdb_moodycamel::ConcurrentQueue< T, Traits >::~ConcurrentQueue ( )
inline
331588 {
331589 // Destroy producers
331590 auto ptr = producerListTail.load(std::memory_order_relaxed);
331591 while (ptr != nullptr) {
331592 auto next = ptr->next_prod();
331593 if (ptr->token != nullptr) {
331594 ptr->token->producer = nullptr;
331595 }
331596 destroy(ptr);
331597 ptr = next;
331598 }
331599
331600 // Destroy implicit producer hash tables
331601 MOODYCAMEL_CONSTEXPR_IF (INITIAL_IMPLICIT_PRODUCER_HASH_SIZE != 0) {
331602 auto hash = implicitProducerHash.load(std::memory_order_relaxed);
331603 while (hash != nullptr) {
331604 auto prev = hash->prev;
331605 if (prev != nullptr) { // The last hash is part of this object and was not allocated dynamically
331606 for (size_t i = 0; i != hash->capacity; ++i) {
331607 hash->entries[i].~ImplicitProducerKVP();
331608 }
331609 hash->~ImplicitProducerHash();
331610 (Traits::free)(hash);
331611 }
331612 hash = prev;
331613 }
331614 }
331615
331616 // Destroy global free list
331617 auto block = freeList.head_unsafe();
331618 while (block != nullptr) {
331619 auto next = block->freeListNext.load(std::memory_order_relaxed);
331620 if (block->dynamicallyAllocated) {
331621 destroy(block);
331622 }
331623 block = next;
331624 }
331625
331626 // Destroy initial free list
331627 destroy_array(initialBlockPool, initialBlockPoolSize);
331628 }

◆ ConcurrentQueue() [3/3]

template<typename T, typename Traits = ConcurrentQueueDefaultTraits>
duckdb_moodycamel::ConcurrentQueue< T, Traits >::ConcurrentQueue ( ConcurrentQueue< T, Traits > && other)
inline
331641 : producerListTail(other.producerListTail.load(std::memory_order_relaxed)),
331642 producerCount(other.producerCount.load(std::memory_order_relaxed)),
331643 initialBlockPoolIndex(other.initialBlockPoolIndex.load(std::memory_order_relaxed)),
331644 initialBlockPool(other.initialBlockPool),
331645 initialBlockPoolSize(other.initialBlockPoolSize),
331646 freeList(std::move(other.freeList)),
331647 nextExplicitConsumerId(other.nextExplicitConsumerId.load(std::memory_order_relaxed)),
331648 globalExplicitConsumerOffset(other.globalExplicitConsumerOffset.load(std::memory_order_relaxed))
331649 {
331650 // Move the other one into this, and leave the other one as an empty queue
331651 implicitProducerHashResizeInProgress.clear(std::memory_order_relaxed);
331652 populate_initial_implicit_producer_hash();
331653 swap_implicit_producer_hashes(other);
331654
331655 other.producerListTail.store(nullptr, std::memory_order_relaxed);
331656 other.producerCount.store(0, std::memory_order_relaxed);
331657 other.nextExplicitConsumerId.store(0, std::memory_order_relaxed);
331658 other.globalExplicitConsumerOffset.store(0, std::memory_order_relaxed);
331659
331660#ifdef MOODYCAMEL_QUEUE_INTERNAL_DEBUG
331662 other.explicitProducers.store(nullptr, std::memory_order_relaxed);
331664 other.implicitProducers.store(nullptr, std::memory_order_relaxed);
331665#endif
331666
331667 other.initialBlockPoolIndex.store(0, std::memory_order_relaxed);
331668 other.initialBlockPoolSize = 0;
331669 other.initialBlockPool = nullptr;
331670
331671 reown_producers();
331672 }

Member Function Documentation

◆ operator=()

template<typename T, typename Traits = ConcurrentQueueDefaultTraits>
ConcurrentQueue & duckdb_moodycamel::ConcurrentQueue< T, Traits >::operator= ( ConcurrentQueue< T, Traits > && other)
inline
331675 {
331676 return swap_internal(other);
331677 }

◆ swap()

template<typename T, typename Traits = ConcurrentQueueDefaultTraits>
void duckdb_moodycamel::ConcurrentQueue< T, Traits >::swap ( ConcurrentQueue< T, Traits > & other)
inline
331685 {
331686 swap_internal(other);
331687 }

◆ swap_internal()

template<typename T, typename Traits = ConcurrentQueueDefaultTraits>
ConcurrentQueue & duckdb_moodycamel::ConcurrentQueue< T, Traits >::swap_internal ( ConcurrentQueue< T, Traits > & other)
inlineprivate
331691 {
331692 if (this == &other) {
331693 return *this;
331694 }
331695
331696 details::swap_relaxed(producerListTail, other.producerListTail);
331697 details::swap_relaxed(producerCount, other.producerCount);
331698 details::swap_relaxed(initialBlockPoolIndex, other.initialBlockPoolIndex);
331699 std::swap(initialBlockPool, other.initialBlockPool);
331700 std::swap(initialBlockPoolSize, other.initialBlockPoolSize);
331701 freeList.swap(other.freeList);
331702 details::swap_relaxed(nextExplicitConsumerId, other.nextExplicitConsumerId);
331703 details::swap_relaxed(globalExplicitConsumerOffset, other.globalExplicitConsumerOffset);
331704
331705 swap_implicit_producer_hashes(other);
331706
331707 reown_producers();
331708 other.reown_producers();
331709
331710#ifdef MOODYCAMEL_QUEUE_INTERNAL_DEBUG
331711 details::swap_relaxed(explicitProducers, other.explicitProducers);
331712 details::swap_relaxed(implicitProducers, other.implicitProducers);
331713#endif
331714
331715 return *this;
331716 }

◆ enqueue() [1/4]

template<typename T, typename Traits = ConcurrentQueueDefaultTraits>
bool duckdb_moodycamel::ConcurrentQueue< T, Traits >::enqueue ( T const & item)
inline
331725 {
331726 MOODYCAMEL_CONSTEXPR_IF (INITIAL_IMPLICIT_PRODUCER_HASH_SIZE == 0) return false;
331727 else return inner_enqueue<CanAlloc>(item);
331728 }

◆ enqueue() [2/4]

template<typename T, typename Traits = ConcurrentQueueDefaultTraits>
bool duckdb_moodycamel::ConcurrentQueue< T, Traits >::enqueue ( T && item)
inline
331736 {
331737 MOODYCAMEL_CONSTEXPR_IF (INITIAL_IMPLICIT_PRODUCER_HASH_SIZE == 0) return false;
331738 else return inner_enqueue<CanAlloc>(std::move(item));
331739 }

◆ enqueue() [3/4]

template<typename T, typename Traits = ConcurrentQueueDefaultTraits>
bool duckdb_moodycamel::ConcurrentQueue< T, Traits >::enqueue ( producer_token_t const & token,
T const & item )
inline
331746 {
331747 return inner_enqueue<CanAlloc>(token, item);
331748 }

◆ enqueue() [4/4]

template<typename T, typename Traits = ConcurrentQueueDefaultTraits>
bool duckdb_moodycamel::ConcurrentQueue< T, Traits >::enqueue ( producer_token_t const & token,
T && item )
inline
331755 {
331756 return inner_enqueue<CanAlloc>(token, std::move(item));
331757 }

◆ enqueue_bulk() [1/2]

template<typename T, typename Traits = ConcurrentQueueDefaultTraits>
template<typename It>
bool duckdb_moodycamel::ConcurrentQueue< T, Traits >::enqueue_bulk ( It itemFirst,
size_t count )
inline
331767 {
331768 MOODYCAMEL_CONSTEXPR_IF (INITIAL_IMPLICIT_PRODUCER_HASH_SIZE == 0) return false;
331769 else return inner_enqueue_bulk<CanAlloc>(itemFirst, count);
331770 }

◆ enqueue_bulk() [2/2]

template<typename T, typename Traits = ConcurrentQueueDefaultTraits>
template<typename It>
bool duckdb_moodycamel::ConcurrentQueue< T, Traits >::enqueue_bulk ( producer_token_t const & token,
It itemFirst,
size_t count )
inline
331780 {
331781 return inner_enqueue_bulk<CanAlloc>(token, itemFirst, count);
331782 }

◆ try_enqueue() [1/4]

template<typename T, typename Traits = ConcurrentQueueDefaultTraits>
bool duckdb_moodycamel::ConcurrentQueue< T, Traits >::try_enqueue ( T const & item)
inline
331790 {
331791 MOODYCAMEL_CONSTEXPR_IF (INITIAL_IMPLICIT_PRODUCER_HASH_SIZE == 0) return false;
331792 else return inner_enqueue<CannotAlloc>(item);
331793 }

◆ try_enqueue() [2/4]

template<typename T, typename Traits = ConcurrentQueueDefaultTraits>
bool duckdb_moodycamel::ConcurrentQueue< T, Traits >::try_enqueue ( T && item)
inline
331801 {
331802 MOODYCAMEL_CONSTEXPR_IF (INITIAL_IMPLICIT_PRODUCER_HASH_SIZE == 0) return false;
331803 else return inner_enqueue<CannotAlloc>(std::move(item));
331804 }

◆ try_enqueue() [3/4]

template<typename T, typename Traits = ConcurrentQueueDefaultTraits>
bool duckdb_moodycamel::ConcurrentQueue< T, Traits >::try_enqueue ( producer_token_t const & token,
T const & item )
inline
331810 {
331811 return inner_enqueue<CannotAlloc>(token, item);
331812 }

◆ try_enqueue() [4/4]

template<typename T, typename Traits = ConcurrentQueueDefaultTraits>
bool duckdb_moodycamel::ConcurrentQueue< T, Traits >::try_enqueue ( producer_token_t const & token,
T && item )
inline
331818 {
331819 return inner_enqueue<CannotAlloc>(token, std::move(item));
331820 }

◆ try_enqueue_bulk() [1/2]

template<typename T, typename Traits = ConcurrentQueueDefaultTraits>
template<typename It>
bool duckdb_moodycamel::ConcurrentQueue< T, Traits >::try_enqueue_bulk ( It itemFirst,
size_t count )
inline
331831 {
331832 MOODYCAMEL_CONSTEXPR_IF (INITIAL_IMPLICIT_PRODUCER_HASH_SIZE == 0) return false;
331833 else return inner_enqueue_bulk<CannotAlloc>(itemFirst, count);
331834 }

◆ try_enqueue_bulk() [2/2]

template<typename T, typename Traits = ConcurrentQueueDefaultTraits>
template<typename It>
bool duckdb_moodycamel::ConcurrentQueue< T, Traits >::try_enqueue_bulk ( producer_token_t const & token,
It itemFirst,
size_t count )
inline
331843 {
331844 return inner_enqueue_bulk<CannotAlloc>(token, itemFirst, count);
331845 }

◆ try_dequeue() [1/2]

template<typename T, typename Traits = ConcurrentQueueDefaultTraits>
template<typename U>
bool duckdb_moodycamel::ConcurrentQueue< T, Traits >::try_dequeue ( U & item)
inline
331855 {
331856 // Instead of simply trying each producer in turn (which could cause needless contention on the first
331857 // producer), we score them heuristically.
331858 size_t nonEmptyCount = 0;
331859 ProducerBase* best = nullptr;
331860 size_t bestSize = 0;
331862 auto size = ptr->size_approx();
331863 if (size > 0) {
331864 if (size > bestSize) {
331865 bestSize = size;
331866 best = ptr;
331867 }
331868 ++nonEmptyCount;
331869 }
331870 }
331871
331872 // If there was at least one non-empty queue but it appears empty at the time
331873 // we try to dequeue from it, we need to make sure every queue's been tried
331874 if (nonEmptyCount > 0) {
331875 if ((details::likely)(best->dequeue(item))) {
331876 return true;
331877 }
331878 for (auto ptr = producerListTail.load(std::memory_order_acquire); ptr != nullptr; ptr = ptr->next_prod()) {
331879 if (ptr != best && ptr->dequeue(item)) {
331880 return true;
331881 }
331882 }
331883 }
331884 return false;
331885 }

◆ try_dequeue_non_interleaved()

template<typename T, typename Traits = ConcurrentQueueDefaultTraits>
template<typename U>
bool duckdb_moodycamel::ConcurrentQueue< T, Traits >::try_dequeue_non_interleaved ( U & item)
inline
331898 {
331899 for (auto ptr = producerListTail.load(std::memory_order_acquire); ptr != nullptr; ptr = ptr->next_prod()) {
331900 if (ptr->dequeue(item)) {
331901 return true;
331902 }
331903 }
331904 return false;
331905 }

◆ try_dequeue() [2/2]

template<typename T, typename Traits = ConcurrentQueueDefaultTraits>
template<typename U>
bool duckdb_moodycamel::ConcurrentQueue< T, Traits >::try_dequeue ( consumer_token_t & token,
U & item )
inline
331913 {
331914 // The idea is roughly as follows:
331915 // Every 256 items from one producer, make everyone rotate (increase the global offset) -> this means the highest efficiency consumer dictates the rotation speed of everyone else, more or less
331916 // If you see that the global offset has changed, you must reset your consumption counter and move to your designated place
331917 // If there's no items where you're supposed to be, keep moving until you find a producer with some items
331918 // If the global offset has not changed but you've run out of items to consume, move over from your current position until you find an producer with something in it
331919
331920 if (token.desiredProducer == nullptr || token.lastKnownGlobalOffset != globalExplicitConsumerOffset.load(std::memory_order_relaxed)) {
331921 if (!update_current_producer_after_rotation(token)) {
331922 return false;
331923 }
331924 }
331925
331926 // If there was at least one non-empty queue but it appears empty at the time
331927 // we try to dequeue from it, we need to make sure every queue's been tried
331928 if (static_cast<ProducerBase*>(token.currentProducer)->dequeue(item)) {
331929 if (++token.itemsConsumedFromCurrent == EXPLICIT_CONSUMER_CONSUMPTION_QUOTA_BEFORE_ROTATE) {
331930 globalExplicitConsumerOffset.fetch_add(1, std::memory_order_relaxed);
331931 }
331932 return true;
331933 }
331934
331935 auto tail = producerListTail.load(std::memory_order_acquire);
331936 auto ptr = static_cast<ProducerBase*>(token.currentProducer)->next_prod();
331937 if (ptr == nullptr) {
331938 ptr = tail;
331939 }
331940 while (ptr != static_cast<ProducerBase*>(token.currentProducer)) {
331941 if (ptr->dequeue(item)) {
331942 token.currentProducer = ptr;
331943 token.itemsConsumedFromCurrent = 1;
331944 return true;
331945 }
331946 ptr = ptr->next_prod();
331947 if (ptr == nullptr) {
331948 ptr = tail;
331949 }
331950 }
331951 return false;
331952 }

◆ try_dequeue_bulk() [1/2]

template<typename T, typename Traits = ConcurrentQueueDefaultTraits>
template<typename It>
size_t duckdb_moodycamel::ConcurrentQueue< T, Traits >::try_dequeue_bulk ( It itemFirst,
size_t max )
inline
331961 {
331962 size_t count = 0;
331963 for (auto ptr = producerListTail.load(std::memory_order_acquire); ptr != nullptr; ptr = ptr->next_prod()) {
331964 count += ptr->dequeue_bulk(itemFirst, max - count);
331965 if (count == max) {
331966 break;
331967 }
331968 }
331969 return count;
331970 }

◆ try_dequeue_bulk() [2/2]

template<typename T, typename Traits = ConcurrentQueueDefaultTraits>
template<typename It>
size_t duckdb_moodycamel::ConcurrentQueue< T, Traits >::try_dequeue_bulk ( consumer_token_t & token,
It itemFirst,
size_t max )
inline
331979 {
331980 if (token.desiredProducer == nullptr || token.lastKnownGlobalOffset != globalExplicitConsumerOffset.load(std::memory_order_relaxed)) {
331981 if (!update_current_producer_after_rotation(token)) {
331982 return 0;
331983 }
331984 }
331985
331986 size_t count = static_cast<ProducerBase*>(token.currentProducer)->dequeue_bulk(itemFirst, max);
331987 if (count == max) {
331988 if ((token.itemsConsumedFromCurrent += static_cast<std::uint32_t>(max)) >= EXPLICIT_CONSUMER_CONSUMPTION_QUOTA_BEFORE_ROTATE) {
331989 globalExplicitConsumerOffset.fetch_add(1, std::memory_order_relaxed);
331990 }
331991 return max;
331992 }
331993 token.itemsConsumedFromCurrent += static_cast<std::uint32_t>(count);
331994 max -= count;
331995
331996 auto tail = producerListTail.load(std::memory_order_acquire);
331997 auto ptr = static_cast<ProducerBase*>(token.currentProducer)->next_prod();
331998 if (ptr == nullptr) {
331999 ptr = tail;
332000 }
332001 while (ptr != static_cast<ProducerBase*>(token.currentProducer)) {
332002 auto dequeued = ptr->dequeue_bulk(itemFirst, max);
332003 count += dequeued;
332004 if (dequeued != 0) {
332005 token.currentProducer = ptr;
332006 token.itemsConsumedFromCurrent = static_cast<std::uint32_t>(dequeued);
332007 }
332008 if (dequeued == max) {
332009 break;
332010 }
332011 max -= dequeued;
332012 ptr = ptr->next_prod();
332013 if (ptr == nullptr) {
332014 ptr = tail;
332015 }
332016 }
332017 return count;
332018 }

◆ try_dequeue_from_producer()

template<typename T, typename Traits = ConcurrentQueueDefaultTraits>
template<typename U>
bool duckdb_moodycamel::ConcurrentQueue< T, Traits >::try_dequeue_from_producer ( producer_token_t const & producer,
U & item )
inline
332030 {
332031 return static_cast<ExplicitProducer*>(producer.producer)->dequeue(item);
332032 }

◆ try_dequeue_bulk_from_producer()

template<typename T, typename Traits = ConcurrentQueueDefaultTraits>
template<typename It>
size_t duckdb_moodycamel::ConcurrentQueue< T, Traits >::try_dequeue_bulk_from_producer ( producer_token_t const & producer,
It itemFirst,
size_t max )
inline
332043 {
332044 return static_cast<ExplicitProducer*>(producer.producer)->dequeue_bulk(itemFirst, max);
332045 }

◆ size_approx()

template<typename T, typename Traits = ConcurrentQueueDefaultTraits>
size_t duckdb_moodycamel::ConcurrentQueue< T, Traits >::size_approx ( ) const
inline
332055 {
332056 size_t size = 0;
332057 for (auto ptr = producerListTail.load(std::memory_order_acquire); ptr != nullptr; ptr = ptr->next_prod()) {
332058 size += ptr->size_approx();
332059 }
332060 return size;
332061 }

◆ size_producers_approx()

template<typename T, typename Traits = ConcurrentQueueDefaultTraits>
size_t duckdb_moodycamel::ConcurrentQueue< T, Traits >::size_producers_approx ( ) const
inline
332066 {
332067 size_t size = 0;
332068 for (auto ptr = producerListTail.load(std::memory_order_acquire); ptr != nullptr; ptr = ptr->next_prod()) {
332069 size += 1;
332070 }
332071 return size;
332072 }

◆ size_producer_approx()

template<typename T, typename Traits = ConcurrentQueueDefaultTraits>
size_t duckdb_moodycamel::ConcurrentQueue< T, Traits >::size_producer_approx ( producer_token_t const & producer) const
inline
332076 {
332077 return static_cast<ExplicitProducer*>(producer.producer)->size_approx();
332078 }

◆ is_lock_free()

◆ inner_enqueue() [1/2]

template<typename T, typename Traits = ConcurrentQueueDefaultTraits>
template<AllocationMode canAlloc, typename U>
bool duckdb_moodycamel::ConcurrentQueue< T, Traits >::inner_enqueue ( producer_token_t const & token,
U && element )
inlineprivate
332114 {
332115 return static_cast<ExplicitProducer*>(token.producer)->ConcurrentQueue::ExplicitProducer::template enqueue<canAlloc>(std::forward<U>(element));
332116 }

◆ inner_enqueue() [2/2]

template<typename T, typename Traits = ConcurrentQueueDefaultTraits>
template<AllocationMode canAlloc, typename U>
bool duckdb_moodycamel::ConcurrentQueue< T, Traits >::inner_enqueue ( U && element)
inlineprivate
332120 {
332121 auto producer = get_or_add_implicit_producer();
332122 return producer == nullptr ? false : producer->ConcurrentQueue::ImplicitProducer::template enqueue<canAlloc>(std::forward<U>(element));
332123 }

◆ inner_enqueue_bulk() [1/2]

template<typename T, typename Traits = ConcurrentQueueDefaultTraits>
template<AllocationMode canAlloc, typename It>
bool duckdb_moodycamel::ConcurrentQueue< T, Traits >::inner_enqueue_bulk ( producer_token_t const & token,
It itemFirst,
size_t count )
inlineprivate
332127 {
332128 return static_cast<ExplicitProducer*>(token.producer)->ConcurrentQueue::ExplicitProducer::template enqueue_bulk<canAlloc>(itemFirst, count);
332129 }

◆ inner_enqueue_bulk() [2/2]

template<typename T, typename Traits = ConcurrentQueueDefaultTraits>
template<AllocationMode canAlloc, typename It>
bool duckdb_moodycamel::ConcurrentQueue< T, Traits >::inner_enqueue_bulk ( It itemFirst,
size_t count )
inlineprivate
332133 {
332134 auto producer = get_or_add_implicit_producer();
332135 return producer == nullptr ? false : producer->ConcurrentQueue::ImplicitProducer::template enqueue_bulk<canAlloc>(itemFirst, count);
332136 }

◆ update_current_producer_after_rotation()

template<typename T, typename Traits = ConcurrentQueueDefaultTraits>
bool duckdb_moodycamel::ConcurrentQueue< T, Traits >::update_current_producer_after_rotation ( consumer_token_t & token)
inlineprivate
332139 {
332140 // Ah, there's been a rotation, figure out where we should be!
332141 auto tail = producerListTail.load(std::memory_order_acquire);
332142 if (token.desiredProducer == nullptr && tail == nullptr) {
332143 return false;
332144 }
332145 auto prodCount = producerCount.load(std::memory_order_relaxed);
332146 auto globalOffset = globalExplicitConsumerOffset.load(std::memory_order_relaxed);
332147 if (token.desiredProducer == nullptr) {
332148 // Aha, first time we're dequeueing anything.
332149 // Figure out our local position
332150 // Note: offset is from start, not end, but we're traversing from end -- subtract from count first
332151 std::uint32_t offset = prodCount - 1 - (token.initialOffset % prodCount);
332152 token.desiredProducer = tail;
332153 for (std::uint32_t i = 0; i != offset; ++i) {
332154 token.desiredProducer = static_cast<ProducerBase*>(token.desiredProducer)->next_prod();
332155 if (token.desiredProducer == nullptr) {
332156 token.desiredProducer = tail;
332157 }
332158 }
332159 }
332160
332161 std::uint32_t delta = globalOffset - token.lastKnownGlobalOffset;
332162 if (delta >= prodCount) {
332163 delta = delta % prodCount;
332164 }
332165 for (std::uint32_t i = 0; i != delta; ++i) {
332166 token.desiredProducer = static_cast<ProducerBase*>(token.desiredProducer)->next_prod();
332167 if (token.desiredProducer == nullptr) {
332168 token.desiredProducer = tail;
332169 }
332170 }
332171
332172 token.lastKnownGlobalOffset = globalOffset;
332173 token.currentProducer = token.desiredProducer;
332174 token.itemsConsumedFromCurrent = 0;
332175 return true;
332176 }

◆ populate_initial_block_list()

template<typename T, typename Traits = ConcurrentQueueDefaultTraits>
void duckdb_moodycamel::ConcurrentQueue< T, Traits >::populate_initial_block_list ( size_t blockCount)
inlineprivate
333781 {
333782 initialBlockPoolSize = blockCount;
333783 if (initialBlockPoolSize == 0) {
333784 initialBlockPool = nullptr;
333785 return;
333786 }
333787
333788 initialBlockPool = create_array<Block>(blockCount);
333789 if (initialBlockPool == nullptr) {
333790 initialBlockPoolSize = 0;
333791 }
333792 for (size_t i = 0; i < initialBlockPoolSize; ++i) {
333793 initialBlockPool[i].dynamicallyAllocated = false;
333794 }
333795 }

◆ try_get_block_from_initial_pool()

template<typename T, typename Traits = ConcurrentQueueDefaultTraits>
Block * duckdb_moodycamel::ConcurrentQueue< T, Traits >::try_get_block_from_initial_pool ( )
inlineprivate
333798 {
333799 if (initialBlockPoolIndex.load(std::memory_order_relaxed) >= initialBlockPoolSize) {
333800 return nullptr;
333801 }
333802
333803 auto index = initialBlockPoolIndex.fetch_add(1, std::memory_order_relaxed);
333804
333805 return index < initialBlockPoolSize ? (initialBlockPool + index) : nullptr;
333806 }

◆ add_block_to_free_list()

template<typename T, typename Traits = ConcurrentQueueDefaultTraits>
void duckdb_moodycamel::ConcurrentQueue< T, Traits >::add_block_to_free_list ( Block * block)
inlineprivate
333809 {
333810#ifdef MCDBGQ_TRACKMEM
333811 block->owner = nullptr;
333812#endif
333813 freeList.add(block);
333814 }

◆ add_blocks_to_free_list()

template<typename T, typename Traits = ConcurrentQueueDefaultTraits>
void duckdb_moodycamel::ConcurrentQueue< T, Traits >::add_blocks_to_free_list ( Block * block)
inlineprivate
333817 {
333818 while (block != nullptr) {
333819 auto next = block->next;
333820 add_block_to_free_list(block);
333821 block = next;
333822 }
333823 }

◆ try_get_block_from_free_list()

template<typename T, typename Traits = ConcurrentQueueDefaultTraits>
Block * duckdb_moodycamel::ConcurrentQueue< T, Traits >::try_get_block_from_free_list ( )
inlineprivate
333826 {
333827 return freeList.try_get();
333828 }

◆ requisition_block()

template<typename T, typename Traits = ConcurrentQueueDefaultTraits>
template<AllocationMode canAlloc>
Block * duckdb_moodycamel::ConcurrentQueue< T, Traits >::requisition_block ( )
inlineprivate
333833 {
333834 auto block = try_get_block_from_initial_pool();
333835 if (block != nullptr) {
333836 return block;
333837 }
333838
333839 block = try_get_block_from_free_list();
333840 if (block != nullptr) {
333841 return block;
333842 }
333843
333844 MOODYCAMEL_CONSTEXPR_IF (canAlloc == CanAlloc) {
333845 return create<Block>();
333846 }
333847 else {
333848 return nullptr;
333849 }
333850 }

◆ recycle_or_create_producer() [1/2]

template<typename T, typename Traits = ConcurrentQueueDefaultTraits>
ProducerBase * duckdb_moodycamel::ConcurrentQueue< T, Traits >::recycle_or_create_producer ( bool isExplicit)
inlineprivate
333964 {
333965 bool recycled;
333966 return recycle_or_create_producer(isExplicit, recycled);
333967 }

◆ recycle_or_create_producer() [2/2]

template<typename T, typename Traits = ConcurrentQueueDefaultTraits>
ProducerBase * duckdb_moodycamel::ConcurrentQueue< T, Traits >::recycle_or_create_producer ( bool isExplicit,
bool & recycled )
inlineprivate
333970 {
333971#ifdef MCDBGQ_NOLOCKFREE_IMPLICITPRODHASH
333973#endif
333974 // Try to re-use one first
333975 for (auto ptr = producerListTail.load(std::memory_order_acquire); ptr != nullptr; ptr = ptr->next_prod()) {
333976 if (ptr->inactive.load(std::memory_order_relaxed) && ptr->isExplicit == isExplicit) {
333977 bool expected = true;
333978 if (ptr->inactive.compare_exchange_strong(expected, /* desired */ false, std::memory_order_acquire, std::memory_order_relaxed)) {
333979 // We caught one! It's been marked as activated, the caller can have it
333980 recycled = true;
333981 return ptr;
333982 }
333983 }
333984 }
333985
333986 recycled = false;
333987 return add_producer(isExplicit ? static_cast<ProducerBase*>(create<ExplicitProducer>(this)) : create<ImplicitProducer>(this));
333988 }

◆ add_producer()

template<typename T, typename Traits = ConcurrentQueueDefaultTraits>
ProducerBase * duckdb_moodycamel::ConcurrentQueue< T, Traits >::add_producer ( ProducerBase * producer)
inlineprivate
333991 {
333992 // Handle failed memory allocation
333993 if (producer == nullptr) {
333994 return nullptr;
333995 }
333996
333997 producerCount.fetch_add(1, std::memory_order_relaxed);
333998
333999 // Add it to the lock-free list
334000 auto prevTail = producerListTail.load(std::memory_order_relaxed);
334001 do {
334002 producer->next = prevTail;
334003 } while (!producerListTail.compare_exchange_weak(prevTail, producer, std::memory_order_release, std::memory_order_relaxed));
334004
334005#ifdef MOODYCAMEL_QUEUE_INTERNAL_DEBUG
334006 if (producer->isExplicit) {
334008 do {
334011 }
334012 else {
334014 do {
334017 }
334018#endif
334019
334020 return producer;
334021 }

◆ reown_producers()

template<typename T, typename Traits = ConcurrentQueueDefaultTraits>
void duckdb_moodycamel::ConcurrentQueue< T, Traits >::reown_producers ( )
inlineprivate
334024 {
334025 // After another instance is moved-into/swapped-with this one, all the
334026 // producers we stole still think their parents are the other queue.
334027 // So fix them up!
334028 for (auto ptr = producerListTail.load(std::memory_order_relaxed); ptr != nullptr; ptr = ptr->next_prod()) {
334029 ptr->parent = this;
334030 }
334031 }

◆ populate_initial_implicit_producer_hash()

template<typename T, typename Traits = ConcurrentQueueDefaultTraits>
void duckdb_moodycamel::ConcurrentQueue< T, Traits >::populate_initial_implicit_producer_hash ( )
inlineprivate
334077 {
334078 MOODYCAMEL_CONSTEXPR_IF (INITIAL_IMPLICIT_PRODUCER_HASH_SIZE == 0) {
334079 return;
334080 }
334081 else {
334082 implicitProducerHashCount.store(0, std::memory_order_relaxed);
334083 auto hash = &initialImplicitProducerHash;
334084 hash->capacity = INITIAL_IMPLICIT_PRODUCER_HASH_SIZE;
334085 hash->entries = &initialImplicitProducerHashEntries[0];
334086 for (size_t i = 0; i != INITIAL_IMPLICIT_PRODUCER_HASH_SIZE; ++i) {
334087 initialImplicitProducerHashEntries[i].key.store(details::invalid_thread_id, std::memory_order_relaxed);
334088 }
334089 hash->prev = nullptr;
334090 implicitProducerHash.store(hash, std::memory_order_relaxed);
334091 }
334092 }

◆ swap_implicit_producer_hashes()

template<typename T, typename Traits = ConcurrentQueueDefaultTraits>
void duckdb_moodycamel::ConcurrentQueue< T, Traits >::swap_implicit_producer_hashes ( ConcurrentQueue< T, Traits > & other)
inlineprivate
334095 {
334096 MOODYCAMEL_CONSTEXPR_IF (INITIAL_IMPLICIT_PRODUCER_HASH_SIZE == 0) {
334097 return;
334098 }
334099 else {
334100 // Swap (assumes our implicit producer hash is initialized)
334101 initialImplicitProducerHashEntries.swap(other.initialImplicitProducerHashEntries);
334102 initialImplicitProducerHash.entries = &initialImplicitProducerHashEntries[0];
334103 other.initialImplicitProducerHash.entries = &other.initialImplicitProducerHashEntries[0];
334104
334105 details::swap_relaxed(implicitProducerHashCount, other.implicitProducerHashCount);
334106
334107 details::swap_relaxed(implicitProducerHash, other.implicitProducerHash);
334108 if (implicitProducerHash.load(std::memory_order_relaxed) == &other.initialImplicitProducerHash) {
334109 implicitProducerHash.store(&initialImplicitProducerHash, std::memory_order_relaxed);
334110 }
334111 else {
334113 for (hash = implicitProducerHash.load(std::memory_order_relaxed); hash->prev != &other.initialImplicitProducerHash; hash = hash->prev) {
334114 continue;
334115 }
334116 hash->prev = &initialImplicitProducerHash;
334117 }
334118 if (other.implicitProducerHash.load(std::memory_order_relaxed) == &initialImplicitProducerHash) {
334119 other.implicitProducerHash.store(&other.initialImplicitProducerHash, std::memory_order_relaxed);
334120 }
334121 else {
334123 for (hash = other.implicitProducerHash.load(std::memory_order_relaxed); hash->prev != &initialImplicitProducerHash; hash = hash->prev) {
334124 continue;
334125 }
334126 hash->prev = &other.initialImplicitProducerHash;
334127 }
334128 }
334129 }

◆ get_or_add_implicit_producer()

template<typename T, typename Traits = ConcurrentQueueDefaultTraits>
ImplicitProducer * duckdb_moodycamel::ConcurrentQueue< T, Traits >::get_or_add_implicit_producer ( )
inlineprivate
334133 {
334134 // Note that since the data is essentially thread-local (key is thread ID),
334135 // there's a reduced need for fences (memory ordering is already consistent
334136 // for any individual thread), except for the current table itself.
334137
334138 // Start by looking for the thread ID in the current and all previous hash tables.
334139 // If it's not found, it must not be in there yet, since this same thread would
334140 // have added it previously to one of the tables that we traversed.
334141
334142 // Code and algorithm adapted from http://preshing.com/20130605/the-worlds-simplest-lock-free-hash-table
334143
334144#ifdef MCDBGQ_NOLOCKFREE_IMPLICITPRODHASH
334146#endif
334147
334148 auto id = details::thread_id();
334150
334151 auto mainHash = implicitProducerHash.load(std::memory_order_acquire);
334152 assert(mainHash != nullptr); // silence clang-tidy and MSVC warnings (hash cannot be null)
334153 for (auto hash = mainHash; hash != nullptr; hash = hash->prev) {
334154 // Look for the id in this hash
334155 auto index = hashedId;
334156 while (true) { // Not an infinite loop because at least one slot is free in the hash table
334157 index &= hash->capacity - 1;
334158
334159 auto probedKey = hash->entries[index].key.load(std::memory_order_relaxed);
334160 if (probedKey == id) {
334161 // Found it! If we had to search several hashes deep, though, we should lazily add it
334162 // to the current main hash table to avoid the extended search next time.
334163 // Note there's guaranteed to be room in the current hash table since every subsequent
334164 // table implicitly reserves space for all previous tables (there's only one
334165 // implicitProducerHashCount).
334166 auto value = hash->entries[index].value;
334167 if (hash != mainHash) {
334168 index = hashedId;
334169 while (true) {
334170 index &= mainHash->capacity - 1;
334171 probedKey = mainHash->entries[index].key.load(std::memory_order_relaxed);
334173#ifdef MOODYCAMEL_CPP11_THREAD_LOCAL_SUPPORTED
334175 if ((probedKey == empty && mainHash->entries[index].key.compare_exchange_strong(empty, id, std::memory_order_relaxed, std::memory_order_relaxed)) ||
334176 (probedKey == reusable && mainHash->entries[index].key.compare_exchange_strong(reusable, id, std::memory_order_acquire, std::memory_order_acquire))) {
334177#else
334178 if ((probedKey == empty && mainHash->entries[index].key.compare_exchange_strong(empty, id, std::memory_order_relaxed, std::memory_order_relaxed))) {
334179#endif
334180 mainHash->entries[index].value = value;
334181 break;
334182 }
334183 ++index;
334184 }
334185 }
334186
334187 return value;
334188 }
334190 break; // Not in this hash table
334191 }
334192 ++index;
334193 }
334194 }
334195
334196 // Insert!
334197 auto newCount = 1 + implicitProducerHashCount.fetch_add(1, std::memory_order_relaxed);
334198 while (true) {
334199 // NOLINTNEXTLINE(clang-analyzer-core.NullDereference)
334200 if (newCount >= (mainHash->capacity >> 1) && !implicitProducerHashResizeInProgress.test_and_set(std::memory_order_acquire)) {
334201 // We've acquired the resize lock, try to allocate a bigger hash table.
334202 // Note the acquire fence synchronizes with the release fence at the end of this block, and hence when
334203 // we reload implicitProducerHash it must be the most recent version (it only gets changed within this
334204 // locked block).
334205 mainHash = implicitProducerHash.load(std::memory_order_acquire);
334206 if (newCount >= (mainHash->capacity >> 1)) {
334207 auto newCapacity = mainHash->capacity << 1;
334208 while (newCount >= (newCapacity >> 1)) {
334209 newCapacity <<= 1;
334210 }
334212 if (raw == nullptr) {
334213 // Allocation failed
334214 implicitProducerHashCount.fetch_sub(1, std::memory_order_relaxed);
334215 implicitProducerHashResizeInProgress.clear(std::memory_order_relaxed);
334216 return nullptr;
334217 }
334218
334219 auto newHash = new (raw) ImplicitProducerHash;
334220 newHash->capacity = newCapacity;
334222 for (size_t i = 0; i != newCapacity; ++i) {
334223 new (newHash->entries + i) ImplicitProducerKVP;
334225 }
334226 newHash->prev = mainHash;
334227 implicitProducerHash.store(newHash, std::memory_order_release);
334228 implicitProducerHashResizeInProgress.clear(std::memory_order_release);
334229 mainHash = newHash;
334230 }
334231 else {
334232 implicitProducerHashResizeInProgress.clear(std::memory_order_release);
334233 }
334234 }
334235
334236 // If it's < three-quarters full, add to the old one anyway so that we don't have to wait for the next table
334237 // to finish being allocated by another thread (and if we just finished allocating above, the condition will
334238 // always be true)
334239 if (newCount < (mainHash->capacity >> 1) + (mainHash->capacity >> 2)) {
334240 bool recycled;
334241 auto producer = static_cast<ImplicitProducer*>(recycle_or_create_producer(false, recycled));
334242 if (producer == nullptr) {
334243 implicitProducerHashCount.fetch_sub(1, std::memory_order_relaxed);
334244 return nullptr;
334245 }
334246 if (recycled) {
334247 implicitProducerHashCount.fetch_sub(1, std::memory_order_relaxed);
334248 }
334249
334250#ifdef MOODYCAMEL_CPP11_THREAD_LOCAL_SUPPORTED
334252 producer->threadExitListener.userData = producer;
334253 details::ThreadExitNotifier::subscribe(&producer->threadExitListener);
334254#endif
334255
334256 auto index = hashedId;
334257 while (true) {
334258 index &= mainHash->capacity - 1;
334259 auto probedKey = mainHash->entries[index].key.load(std::memory_order_relaxed);
334260
334262#ifdef MOODYCAMEL_CPP11_THREAD_LOCAL_SUPPORTED
334264 if ((probedKey == empty && mainHash->entries[index].key.compare_exchange_strong(empty, id, std::memory_order_relaxed, std::memory_order_relaxed)) ||
334265 (probedKey == reusable && mainHash->entries[index].key.compare_exchange_strong(reusable, id, std::memory_order_acquire, std::memory_order_acquire))) {
334266#else
334267 if ((probedKey == empty && mainHash->entries[index].key.compare_exchange_strong(empty, id, std::memory_order_relaxed, std::memory_order_relaxed))) {
334268#endif
334269 mainHash->entries[index].value = producer;
334270 break;
334271 }
334272 ++index;
334273 }
334274 return producer;
334275 }
334276
334277 // Hmm, the old hash is quite full and somebody else is busy allocating a new one.
334278 // We need to wait for the allocating thread to finish (if it succeeds, we add, if not,
334279 // we try to allocate ourselves).
334280 mainHash = implicitProducerHash.load(std::memory_order_acquire);
334281 }
334282 }
#define assert(x)
Definition duckdb.cpp:486071

◆ aligned_malloc()

template<typename T, typename Traits = ConcurrentQueueDefaultTraits>
template<typename TAlign>
void * duckdb_moodycamel::ConcurrentQueue< T, Traits >::aligned_malloc ( size_t size)
inlinestaticprivate
334333 {
334335 return (Traits::malloc)(size);
334337 void* raw = (Traits::malloc)(size + alignment - 1 + sizeof(void*));
334338 if (!raw)
334339 return nullptr;
334340 char* ptr = details::align_for<TAlign>(reinterpret_cast<char*>(raw) + sizeof(void*));
334341 *(reinterpret_cast<void**>(ptr) - 1) = raw;
334342 return ptr;
334343 }

◆ aligned_free()

template<typename T, typename Traits = ConcurrentQueueDefaultTraits>
template<typename TAlign>
void duckdb_moodycamel::ConcurrentQueue< T, Traits >::aligned_free ( void * ptr)
inlinestaticprivate
334347 {
334349 return (Traits::free)(ptr);
334350 (Traits::free)(ptr ? *(reinterpret_cast<void**>(ptr) - 1) : nullptr);
334351 }

◆ create_array()

template<typename T, typename Traits = ConcurrentQueueDefaultTraits>
template<typename U>
U * duckdb_moodycamel::ConcurrentQueue< T, Traits >::create_array ( size_t count)
inlinestaticprivate
334355 {
334356 assert(count > 0);
334357 U* p = static_cast<U*>(aligned_malloc<U>(sizeof(U) * count));
334358 if (p == nullptr)
334359 return nullptr;
334360
334361 for (size_t i = 0; i != count; ++i)
334362 new (p + i) U();
334363 return p;
334364 }

◆ destroy_array()

template<typename T, typename Traits = ConcurrentQueueDefaultTraits>
template<typename U>
void duckdb_moodycamel::ConcurrentQueue< T, Traits >::destroy_array ( U * p,
size_t count )
inlinestaticprivate
334368 {
334369 if (p != nullptr) {
334370 assert(count > 0);
334371 for (size_t i = count; i != 0; )
334372 (p + --i)->~U();
334373 }
334374 aligned_free<U>(p);
334375 }

◆ create() [1/2]

template<typename T, typename Traits = ConcurrentQueueDefaultTraits>
template<typename U>
U * duckdb_moodycamel::ConcurrentQueue< T, Traits >::create ( )
inlinestaticprivate
334379 {
334380 void* p = aligned_malloc<U>(sizeof(U));
334381 return p != nullptr ? new (p) U : nullptr;
334382 }

◆ create() [2/2]

template<typename T, typename Traits = ConcurrentQueueDefaultTraits>
template<typename U, typename A1>
U * duckdb_moodycamel::ConcurrentQueue< T, Traits >::create ( A1 && a1)
inlinestaticprivate
334386 {
334387 void* p = aligned_malloc<U>(sizeof(U));
334388 return p != nullptr ? new (p) U(std::forward<A1>(a1)) : nullptr;
334389 }

◆ destroy()

template<typename T, typename Traits = ConcurrentQueueDefaultTraits>
template<typename U>
void duckdb_moodycamel::ConcurrentQueue< T, Traits >::destroy ( U * p)
inlinestaticprivate
334393 {
334394 if (p != nullptr)
334395 p->~U();
334396 aligned_free<U>(p);
334397 }

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