proxygen
|
#include <UnboundedQueue.h>
Classes | |
struct | Consumer |
class | Entry |
struct | Producer |
class | Segment |
Public Member Functions | |
UnboundedQueue () | |
~UnboundedQueue () | |
FOLLY_ALWAYS_INLINE void | enqueue (const T &arg) |
FOLLY_ALWAYS_INLINE void | enqueue (T &&arg) |
FOLLY_ALWAYS_INLINE void | dequeue (T &item) noexcept |
FOLLY_ALWAYS_INLINE bool | try_dequeue (T &item) noexcept |
FOLLY_ALWAYS_INLINE folly::Optional< T > | try_dequeue () noexcept |
template<typename Clock , typename Duration > | |
FOLLY_ALWAYS_INLINE bool | try_dequeue_until (T &item, const std::chrono::time_point< Clock, Duration > &deadline) noexcept |
template<typename Clock , typename Duration > | |
FOLLY_ALWAYS_INLINE folly::Optional< T > | try_dequeue_until (const std::chrono::time_point< Clock, Duration > &deadline) noexcept |
template<typename Rep , typename Period > | |
FOLLY_ALWAYS_INLINE bool | try_dequeue_for (T &item, const std::chrono::duration< Rep, Period > &duration) noexcept |
template<typename Rep , typename Period > | |
FOLLY_ALWAYS_INLINE folly::Optional< T > | try_dequeue_for (const std::chrono::duration< Rep, Period > &duration) noexcept |
FOLLY_ALWAYS_INLINE const T * | try_peek () noexcept |
size_t | size () const noexcept |
bool | empty () const noexcept |
Private Types | |
using | Ticket = uint64_t |
Private Member Functions | |
template<typename Arg > | |
FOLLY_ALWAYS_INLINE void | enqueueImpl (Arg &&arg) |
template<typename Arg > | |
FOLLY_ALWAYS_INLINE void | enqueueCommon (Segment *s, Arg &&arg) |
FOLLY_ALWAYS_INLINE void | dequeueImpl (T &item) noexcept |
FOLLY_ALWAYS_INLINE void | dequeueCommon (Segment *s, T &item) noexcept |
template<typename Clock , typename Duration > | |
FOLLY_ALWAYS_INLINE folly::Optional< T > | tryDequeueUntil (const std::chrono::time_point< Clock, Duration > &deadline) noexcept |
template<typename Clock , typename Duration > | |
FOLLY_ALWAYS_INLINE folly::Optional< T > | tryDequeueUntilSC (Segment *s, const std::chrono::time_point< Clock, Duration > &deadline) noexcept |
template<typename Clock , typename Duration > | |
FOLLY_ALWAYS_INLINE folly::Optional< T > | tryDequeueUntilMC (Segment *s, const std::chrono::time_point< Clock, Duration > &deadline) noexcept |
template<typename Clock , typename Duration > | |
FOLLY_ALWAYS_INLINE bool | tryDequeueWaitElem (Entry &e, Ticket t, const std::chrono::time_point< Clock, Duration > &deadline) noexcept |
template<typename Clock , typename Duration > | |
FOLLY_ALWAYS_INLINE const T * | tryPeekUntil (const std::chrono::time_point< Clock, Duration > &deadline) noexcept |
FOLLY_ALWAYS_INLINE Segment * | findSegment (Segment *s, const Ticket t) noexcept |
Segment * | getAllocNextSegment (Segment *s, Ticket t) noexcept |
Segment * | allocNextSegment (Segment *s) |
void | advanceTail (Segment *s) noexcept |
void | advanceTailToTicket (Ticket t) noexcept |
void | advanceHead (Segment *s) noexcept |
void | advanceHeadToTicket (Ticket t) noexcept |
void | reclaimSegment (Segment *s) noexcept |
void | cleanUpRemainingItems () |
void | reclaimRemainingSegments () |
FOLLY_ALWAYS_INLINE size_t | index (Ticket t) const noexcept |
FOLLY_ALWAYS_INLINE bool | responsibleForAlloc (Ticket t) const noexcept |
FOLLY_ALWAYS_INLINE bool | responsibleForAdvance (Ticket t) const noexcept |
FOLLY_ALWAYS_INLINE Segment * | head () const noexcept |
FOLLY_ALWAYS_INLINE Segment * | tail () const noexcept |
FOLLY_ALWAYS_INLINE Ticket | producerTicket () const noexcept |
FOLLY_ALWAYS_INLINE Ticket | consumerTicket () const noexcept |
void | setHead (Segment *s) noexcept |
void | setTail (Segment *s) noexcept |
bool | casHead (Segment *&s, Segment *next) noexcept |
void | casTail (Segment *&s, Segment *next) noexcept |
FOLLY_ALWAYS_INLINE void | setProducerTicket (Ticket t) noexcept |
FOLLY_ALWAYS_INLINE void | setConsumerTicket (Ticket t) noexcept |
FOLLY_ALWAYS_INLINE Ticket | fetchIncrementConsumerTicket () noexcept |
FOLLY_ALWAYS_INLINE Ticket | fetchIncrementProducerTicket () noexcept |
Private Attributes | |
Consumer | c_ |
Producer | p_ |
Static Private Attributes | |
static constexpr bool | SPSC = SingleProducer && SingleConsumer |
static constexpr size_t | Stride = SPSC || (LgSegmentSize <= 1) ? 1 : 27 |
static constexpr size_t | SegmentSize = 1u << LgSegmentSize |
static constexpr size_t | Align = 1u << LgAlign |
UnboundedQueue supports a variety of options for unbounded dynamically expanding an shrinking queues, including variations of:
Template parameters:
When to use UnboundedQueue:
When not to use UnboundedQueue:
Template Aliases: USPSCQueue<T, MayBlock, LgSegmentSize, LgAlign> UMPSCQueue<T, MayBlock, LgSegmentSize, LgAlign> USPMCQueue<T, MayBlock, LgSegmentSize, LgAlign> UMPMCQueue<T, MayBlock, LgSegmentSize, LgAlign>
Functions: Producer operations never wait or fail (unless OOM) void enqueue(const T&); void enqueue(T&&); Adds an element to the end of the queue.
Consumer operations: void dequeue(T&); Extracts an element from the front of the queue. Waits until an element is available if needed. bool try_dequeue(T&); folly::Optional<T> try_dequeue(); Tries to extract an element from the front of the queue if available. bool try_dequeue_until(T&, time_point& deadline); folly::Optional<T> try_dequeue_until(time_point& deadline); Tries to extract an element from the front of the queue if available until the specified deadline. bool try_dequeue_for(T&, duration&); folly::Optional<T> try_dequeue_for(duration&); Tries to extract an element from the front of the queue if available until the expiration of the specified duration. const T* try_peek(); Returns pointer to the element at the front of the queue if available, or nullptr if the queue is empty. Only for SPSC and MPSC.
Secondary functions: size_t size(); Returns an estimate of the size of the queue. bool empty(); Returns true only if the queue was empty during the call. Note: size() and empty() are guaranteed to be accurate only if the queue is not changed concurrently.
Usage examples:
Design:
Memory Usage:
Performance considerations:
Definition at line 216 of file UnboundedQueue.h.
|
private |
Definition at line 217 of file UnboundedQueue.h.
|
inline |
|
inline |
destructor
Definition at line 253 of file UnboundedQueue.h.
|
inlineprivatenoexcept |
advanceHead
Definition at line 586 of file UnboundedQueue.h.
Referenced by folly::UnboundedQueue< T, false, 6 >::dequeueCommon(), folly::UnboundedQueue< T, false, 6 >::tryDequeueUntilMC(), and folly::UnboundedQueue< T, false, 6 >::tryDequeueUntilSC().
|
inlineprivatenoexcept |
advanceHeadToTicket
Definition at line 603 of file UnboundedQueue.h.
Referenced by folly::UnboundedQueue< T, false, 6 >::advanceHead().
|
inlineprivatenoexcept |
advanceTail
Definition at line 560 of file UnboundedQueue.h.
Referenced by folly::UnboundedQueue< T, false, 6 >::enqueueCommon().
|
inlineprivatenoexcept |
advanceTailToTicket
Definition at line 572 of file UnboundedQueue.h.
Referenced by folly::UnboundedQueue< T, false, 6 >::advanceHeadToTicket(), and folly::UnboundedQueue< T, false, 6 >::advanceTail().
|
inlineprivate |
allocNextSegment
Definition at line 547 of file UnboundedQueue.h.
Referenced by folly::UnboundedQueue< T, false, 6 >::advanceTailToTicket(), folly::UnboundedQueue< T, false, 6 >::enqueueCommon(), and folly::UnboundedQueue< T, false, 6 >::getAllocNextSegment().
|
inlineprivatenoexcept |
Definition at line 701 of file UnboundedQueue.h.
Referenced by folly::UnboundedQueue< T, false, 6 >::advanceHeadToTicket().
|
inlineprivatenoexcept |
Definition at line 707 of file UnboundedQueue.h.
Referenced by folly::UnboundedQueue< T, false, 6 >::advanceTailToTicket().
|
inlineprivate |
cleanUpRemainingItems
Definition at line 636 of file UnboundedQueue.h.
Referenced by folly::UnboundedQueue< T, false, 6 >::~UnboundedQueue().
|
inlineprivatenoexcept |
Definition at line 687 of file UnboundedQueue.h.
Referenced by folly::UnboundedQueue< T, false, 6 >::cleanUpRemainingItems(), folly::UnboundedQueue< T, false, 6 >::empty(), folly::UnboundedQueue< T, false, 6 >::fetchIncrementConsumerTicket(), folly::UnboundedQueue< T, false, 6 >::size(), folly::UnboundedQueue< T, false, 6 >::tryDequeueUntilMC(), folly::UnboundedQueue< T, false, 6 >::tryDequeueUntilSC(), and folly::UnboundedQueue< T, false, 6 >::tryPeekUntil().
|
inlinenoexcept |
dequeue
Definition at line 268 of file UnboundedQueue.h.
Referenced by enq_deq_test().
|
inlineprivatenoexcept |
dequeueCommon
Definition at line 405 of file UnboundedQueue.h.
Referenced by folly::UnboundedQueue< T, false, 6 >::dequeueImpl().
|
inlineprivatenoexcept |
dequeueImpl
Definition at line 390 of file UnboundedQueue.h.
Referenced by folly::UnboundedQueue< T, false, 6 >::dequeue().
|
inlinenoexcept |
empty
Definition at line 347 of file UnboundedQueue.h.
|
inline |
enqueue
Definition at line 259 of file UnboundedQueue.h.
Referenced by enq_deq_test(), and TEST().
|
inline |
Definition at line 263 of file UnboundedQueue.h.
|
inlineprivate |
enqueueCommon
Definition at line 371 of file UnboundedQueue.h.
Referenced by folly::UnboundedQueue< T, false, 6 >::enqueueImpl().
|
inlineprivate |
enqueueImpl
Definition at line 356 of file UnboundedQueue.h.
Referenced by folly::UnboundedQueue< T, false, 6 >::enqueue().
|
inlineprivatenoexcept |
Definition at line 721 of file UnboundedQueue.h.
Referenced by folly::UnboundedQueue< T, false, 6 >::dequeueCommon().
|
inlineprivatenoexcept |
Definition at line 731 of file UnboundedQueue.h.
Referenced by folly::UnboundedQueue< T, false, 6 >::enqueueCommon().
|
inlineprivatenoexcept |
findSegment
Definition at line 514 of file UnboundedQueue.h.
Referenced by folly::UnboundedQueue< T, false, 6 >::dequeueCommon(), and folly::UnboundedQueue< T, false, 6 >::enqueueCommon().
|
inlineprivatenoexcept |
getAllocNextSegment
Definition at line 523 of file UnboundedQueue.h.
Referenced by folly::UnboundedQueue< T, false, 6 >::findSegment(), and folly::UnboundedQueue< T, false, 6 >::tryDequeueUntilMC().
|
inlineprivatenoexcept |
Definition at line 675 of file UnboundedQueue.h.
|
inlineprivatenoexcept |
Definition at line 663 of file UnboundedQueue.h.
Referenced by folly::UnboundedQueue< T, false, 6 >::cleanUpRemainingItems(), folly::UnboundedQueue< T, false, 6 >::dequeueCommon(), folly::UnboundedQueue< T, false, 6 >::enqueueCommon(), folly::UnboundedQueue< T, SingleProducer, SingleConsumer, MayBlock, LgSegmentSize, LgAlign, Atom >::Segment::entry(), folly::UnboundedQueue< T, false, 6 >::tryDequeueUntilMC(), folly::UnboundedQueue< T, false, 6 >::tryDequeueUntilSC(), and folly::UnboundedQueue< T, false, 6 >::tryPeekUntil().
|
inlineprivatenoexcept |
Definition at line 683 of file UnboundedQueue.h.
Referenced by folly::UnboundedQueue< T, false, 6 >::cleanUpRemainingItems(), folly::UnboundedQueue< T, false, 6 >::empty(), folly::UnboundedQueue< T, false, 6 >::fetchIncrementProducerTicket(), folly::UnboundedQueue< T, false, 6 >::size(), and folly::UnboundedQueue< T, false, 6 >::tryDequeueWaitElem().
|
inlineprivate |
reclaimRemainingSegments
Definition at line 651 of file UnboundedQueue.h.
Referenced by folly::UnboundedQueue< T, false, 6 >::~UnboundedQueue().
|
inlineprivatenoexcept |
reclaimSegment
Definition at line 627 of file UnboundedQueue.h.
Referenced by folly::UnboundedQueue< T, false, 6 >::advanceHead(), folly::UnboundedQueue< T, false, 6 >::advanceHeadToTicket(), and folly::UnboundedQueue< T, false, 6 >::reclaimRemainingSegments().
|
inlineprivatenoexcept |
Definition at line 671 of file UnboundedQueue.h.
Referenced by folly::UnboundedQueue< T, false, 6 >::dequeueCommon(), folly::UnboundedQueue< T, false, 6 >::enqueueCommon(), folly::UnboundedQueue< T, false, 6 >::tryDequeueUntilMC(), and folly::UnboundedQueue< T, false, 6 >::tryDequeueUntilSC().
|
inlineprivatenoexcept |
Definition at line 667 of file UnboundedQueue.h.
Referenced by folly::UnboundedQueue< T, false, 6 >::enqueueCommon().
|
inlineprivatenoexcept |
Definition at line 717 of file UnboundedQueue.h.
Referenced by folly::UnboundedQueue< T, false, 6 >::fetchIncrementConsumerTicket(), and folly::UnboundedQueue< T, false, 6 >::tryDequeueUntilSC().
|
inlineprivatenoexcept |
Definition at line 691 of file UnboundedQueue.h.
Referenced by folly::UnboundedQueue< T, false, 6 >::advanceHead(), and folly::UnboundedQueue< T, false, 6 >::advanceHeadToTicket().
|
inlineprivatenoexcept |
Definition at line 713 of file UnboundedQueue.h.
Referenced by folly::UnboundedQueue< T, false, 6 >::fetchIncrementProducerTicket().
|
inlineprivatenoexcept |
Definition at line 696 of file UnboundedQueue.h.
Referenced by folly::UnboundedQueue< T, false, 6 >::advanceTail().
|
inlinenoexcept |
size
Definition at line 340 of file UnboundedQueue.h.
|
inlineprivatenoexcept |
Definition at line 679 of file UnboundedQueue.h.
Referenced by folly::UnboundedQueue< T, false, 6 >::advanceHead(), folly::UnboundedQueue< T, false, 6 >::advanceTailToTicket(), and folly::UnboundedQueue< T, false, 6 >::enqueueImpl().
|
inlinenoexcept |
try_dequeue
Definition at line 273 of file UnboundedQueue.h.
Referenced by enq_deq_test().
|
inlinenoexcept |
Definition at line 282 of file UnboundedQueue.h.
Referenced by folly::UnboundedQueue< T, false, 6 >::try_dequeue(), and folly::UnboundedQueue< T, false, 6 >::try_dequeue_for().
|
inlinenoexcept |
try_dequeue_for
Definition at line 309 of file UnboundedQueue.h.
Referenced by enq_deq_test(), and folly::UnboundedQueue< T, false, 6 >::try_dequeue_for().
|
inlinenoexcept |
Definition at line 323 of file UnboundedQueue.h.
|
inlinenoexcept |
try_dequeue_until
Definition at line 288 of file UnboundedQueue.h.
Referenced by folly::UnboundedQueue< T, false, 6 >::try_dequeue_until().
|
inlinenoexcept |
Definition at line 302 of file UnboundedQueue.h.
|
inlinenoexcept |
try_peek
Definition at line 333 of file UnboundedQueue.h.
Referenced by enq_deq_test().
|
inlineprivatenoexcept |
tryDequeueUntil
Definition at line 420 of file UnboundedQueue.h.
Referenced by folly::UnboundedQueue< T, false, 6 >::try_dequeue(), folly::UnboundedQueue< T, false, 6 >::try_dequeue_for(), and folly::UnboundedQueue< T, false, 6 >::try_dequeue_until().
|
inlineprivatenoexcept |
tryDequeueUntilMC
Definition at line 457 of file UnboundedQueue.h.
Referenced by folly::UnboundedQueue< T, false, 6 >::tryDequeueUntil().
|
inlineprivatenoexcept |
tryDequeueUntilSC
Definition at line 436 of file UnboundedQueue.h.
Referenced by folly::UnboundedQueue< T, false, 6 >::tryDequeueUntil().
|
inlineprivatenoexcept |
tryDequeueWaitElem
Definition at line 486 of file UnboundedQueue.h.
Referenced by folly::UnboundedQueue< T, false, 6 >::tryDequeueUntilMC(), folly::UnboundedQueue< T, false, 6 >::tryDequeueUntilSC(), and folly::UnboundedQueue< T, false, 6 >::tryPeekUntil().
|
inlineprivatenoexcept |
tryPeekUntil
Definition at line 498 of file UnboundedQueue.h.
Referenced by folly::UnboundedQueue< T, false, 6 >::try_peek().
|
staticprivate |
Definition at line 224 of file UnboundedQueue.h.
|
private |
Definition at line 244 of file UnboundedQueue.h.
Referenced by folly::UnboundedQueue< T, false, 6 >::casHead(), folly::UnboundedQueue< T, false, 6 >::consumerTicket(), folly::UnboundedQueue< T, false, 6 >::dequeueImpl(), folly::UnboundedQueue< T, false, 6 >::fetchIncrementConsumerTicket(), folly::UnboundedQueue< T, false, 6 >::head(), folly::UnboundedQueue< T, false, 6 >::setConsumerTicket(), folly::UnboundedQueue< T, false, 6 >::setHead(), folly::UnboundedQueue< T, false, 6 >::tryDequeueUntil(), and folly::UnboundedQueue< T, false, 6 >::tryDequeueUntilMC().
|
private |
Definition at line 245 of file UnboundedQueue.h.
Referenced by folly::UnboundedQueue< T, false, 6 >::casTail(), folly::UnboundedQueue< T, false, 6 >::enqueueImpl(), folly::UnboundedQueue< T, false, 6 >::fetchIncrementProducerTicket(), folly::UnboundedQueue< T, false, 6 >::producerTicket(), folly::UnboundedQueue< T, false, 6 >::setProducerTicket(), folly::UnboundedQueue< T, false, 6 >::setTail(), and folly::UnboundedQueue< T, false, 6 >::tail().
|
staticprivate |
Definition at line 223 of file UnboundedQueue.h.
Referenced by folly::UnboundedQueue< T, false, 6 >::advanceHead(), folly::UnboundedQueue< T, false, 6 >::advanceHeadToTicket(), folly::UnboundedQueue< T, false, 6 >::advanceTail(), folly::UnboundedQueue< T, false, 6 >::allocNextSegment(), folly::UnboundedQueue< T, false, 6 >::cleanUpRemainingItems(), folly::UnboundedQueue< T, false, 6 >::enqueueCommon(), folly::UnboundedQueue< T, false, 6 >::findSegment(), folly::UnboundedQueue< T, false, 6 >::getAllocNextSegment(), folly::UnboundedQueue< T, false, 6 >::tryDequeueUntilMC(), folly::UnboundedQueue< T, false, 6 >::tryDequeueUntilSC(), and folly::UnboundedQueue< T, false, 6 >::tryPeekUntil().
|
staticprivate |
Definition at line 221 of file UnboundedQueue.h.
|
staticprivate |
Definition at line 222 of file UnboundedQueue.h.