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 >::FreeList< N > Struct Template Reference

Public Member Functions

 FreeList (FreeList &&other)
void swap (FreeList &other)
 FreeList (FreeList const &) MOODYCAMEL_DELETE_FUNCTION
FreeList & operator= (FreeList const &) MOODYCAMEL_DELETE_FUNCTION
void add (N *node)
N * try_get ()
N * head_unsafe () const

Private Member Functions

void add_knowing_refcount_is_zero (N *node)

Private Attributes

std::atomic< N * > freeListHead

Static Private Attributes

static const std::uint32_t REFS_MASK = 0x7FFFFFFF
static const std::uint32_t SHOULD_BE_ON_FREELIST = 0x80000000

Constructor & Destructor Documentation

◆ FreeList() [1/2]

template<typename T, typename Traits = ConcurrentQueueDefaultTraits>
template<typename N>
duckdb_moodycamel::ConcurrentQueue< T, Traits >::FreeList< N >::FreeList ( )
inline
332198: freeListHead(nullptr) { }

◆ FreeList() [2/2]

template<typename T, typename Traits = ConcurrentQueueDefaultTraits>
template<typename N>
duckdb_moodycamel::ConcurrentQueue< T, Traits >::FreeList< N >::FreeList ( FreeList< N > && other)
inline
332199: freeListHead(other.freeListHead.load(std::memory_order_relaxed)) { other.freeListHead.store(nullptr, std::memory_order_relaxed); }
Definition duckdb.cpp:331497

Member Function Documentation

◆ swap()

template<typename T, typename Traits = ConcurrentQueueDefaultTraits>
template<typename N>
void duckdb_moodycamel::ConcurrentQueue< T, Traits >::FreeList< N >::swap ( FreeList< N > & other)
inline
332200{ details::swap_relaxed(freeListHead, other.freeListHead); }

◆ add()

template<typename T, typename Traits = ConcurrentQueueDefaultTraits>
template<typename N>
void duckdb_moodycamel::ConcurrentQueue< T, Traits >::FreeList< N >::add ( N * node)
inline
332206 {
332207#ifdef MCDBGQ_NOLOCKFREE_FREELIST
332209#endif
332210 // We know that the should-be-on-freelist bit is 0 at this point, so it's safe to
332211 // set it using a fetch_add
332212 if (node->freeListRefs.fetch_add(SHOULD_BE_ON_FREELIST, std::memory_order_acq_rel) == 0) {
332213 // Oh look! We were the last ones referencing this node, and we know
332214 // we want to add it to the free list, so let's do it!
332215 add_knowing_refcount_is_zero(node);
332216 }
332217 }

◆ try_get()

template<typename T, typename Traits = ConcurrentQueueDefaultTraits>
template<typename N>
N * duckdb_moodycamel::ConcurrentQueue< T, Traits >::FreeList< N >::try_get ( )
inline
332220 {
332221#ifdef MCDBGQ_NOLOCKFREE_FREELIST
332223#endif
332224 auto head = freeListHead.load(std::memory_order_acquire);
332225 while (head != nullptr) {
332226 auto prevHead = head;
332227 auto refs = head->freeListRefs.load(std::memory_order_relaxed);
332228 if ((refs & REFS_MASK) == 0 || !head->freeListRefs.compare_exchange_strong(refs, refs + 1, std::memory_order_acquire, std::memory_order_relaxed)) {
332229 head = freeListHead.load(std::memory_order_acquire);
332230 continue;
332231 }
332232
332233 // Good, reference count has been incremented (it wasn't at zero), which means we can read the
332234 // next and not worry about it changing between now and the time we do the CAS
332235 auto next = head->freeListNext.load(std::memory_order_relaxed);
332236 if (freeListHead.compare_exchange_strong(head, next, std::memory_order_acquire, std::memory_order_relaxed)) {
332237 // Yay, got the node. This means it was on the list, which means shouldBeOnFreeList must be false no
332238 // matter the refcount (because nobody else knows it's been taken off yet, it can't have been put back on).
332239 assert((head->freeListRefs.load(std::memory_order_relaxed) & SHOULD_BE_ON_FREELIST) == 0);
332240
332241 // Decrease refcount twice, once for our ref, and once for the list's ref
332242 head->freeListRefs.fetch_sub(2, std::memory_order_release);
332243 return head;
332244 }
332245
332246 // OK, the head must have changed on us, but we still need to decrease the refcount we increased.
332247 // Note that we don't need to release any memory effects, but we do need to ensure that the reference
332248 // count decrement happens-after the CAS on the head.
332249 refs = prevHead->freeListRefs.fetch_sub(1, std::memory_order_acq_rel);
332250 if (refs == SHOULD_BE_ON_FREELIST + 1) {
332251 add_knowing_refcount_is_zero(prevHead);
332252 }
332253 }
332254
332255 return nullptr;
332256 }
#define assert(x)
Definition duckdb.cpp:486071

◆ head_unsafe()

template<typename T, typename Traits = ConcurrentQueueDefaultTraits>
template<typename N>
N * duckdb_moodycamel::ConcurrentQueue< T, Traits >::FreeList< N >::head_unsafe ( ) const
inline
332259{ return freeListHead.load(std::memory_order_relaxed); }

◆ add_knowing_refcount_is_zero()

template<typename T, typename Traits = ConcurrentQueueDefaultTraits>
template<typename N>
void duckdb_moodycamel::ConcurrentQueue< T, Traits >::FreeList< N >::add_knowing_refcount_is_zero ( N * node)
inlineprivate
332263 {
332264 // Since the refcount is zero, and nobody can increase it once it's zero (except us, and we run
332265 // only one copy of this method per node at a time, i.e. the single thread case), then we know
332266 // we can safely change the next pointer of the node; however, once the refcount is back above
332267 // zero, then other threads could increase it (happens under heavy contention, when the refcount
332268 // goes to zero in between a load and a refcount increment of a node in try_get, then back up to
332269 // something non-zero, then the refcount increment is done by the other thread) -- so, if the CAS
332270 // to add the node to the actual list fails, decrease the refcount and leave the add operation to
332271 // the next thread who puts the refcount back at zero (which could be us, hence the loop).
332272 auto head = freeListHead.load(std::memory_order_relaxed);
332273 while (true) {
332274 node->freeListNext.store(head, std::memory_order_relaxed);
332275 node->freeListRefs.store(1, std::memory_order_release);
332276 if (!freeListHead.compare_exchange_strong(head, node, std::memory_order_release, std::memory_order_relaxed)) {
332277 // Hmm, the add failed, but we can only try again when the refcount goes back to zero
332278 if (node->freeListRefs.fetch_add(SHOULD_BE_ON_FREELIST - 1, std::memory_order_release) == 1) {
332279 continue;
332280 }
332281 }
332282 return;
332283 }
332284 }

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