ark::concurrency::LocklessQueue
Defined in header “ark/concurrency/lockless_queue.hh”.
A lock-free/wait-free/alloc-free multi-producer/multi-subscriber queue, which favors newer items over older items. This is optimized to allow consumers to make progress at all costs, even when crossing thread priority boundaries.
It is primarily intended for situations in which you might have different priority threads pushing and popping. It will most likely be a bit slower than a typical mutex/queue pair, but is aimed at preventing priority inversion.
Methods
-
LocklessQueue(size_t queue_size)
Initializes a new queue with the given size. -
LocklessQueue(size_t queue_size, size_t freelist_overhead)
Initializes a new queue with the given size and free list overhead. If you expect to have a lot of parallelism, and expect to drop data from the queue while emplacing it, then you might want to increase this number. It allows you to add to the queue before items are removed (so, for small queue sizes, you are less likely to see spurious drops). -
~LocklessQueue()
Destructor, releases memory. -
LocklessQueue(const LocklessQueue & other)
Deleted copy constructor. -
LocklessQueue(LocklessQueue && other)
Deleted move constructor. -
LocklessQueue & operator=(const LocklessQueue & other)
Deleted copy operator. -
LocklessQueue & operator=(LocklessQueue && other)
Deleted move operator. -
size_t max_queue_size()
Returns the maximum queue size, as defined by the user. -
LocklessQueuePushState push(const Type & value, LocklessQueuePushOptions options)
Pushes an item onto the given queue. If the queue is full, the item on the front of the queue will be dropped. Returns true if the push was successful without a drop, false otherwise. -
LocklessQueuePushState emplace(Type && value, LocklessQueuePushOptions options)
Pushes an item onto the given queue. If the queue is full, the item on the front of the queue will be dropped. Returns a state enumeration indicating how the push operation went. -
bool pop()
Pops an element off the queue, returning true if successful and false if there is nothing left on the queue. -
void pop_all()
Pops all elements off the queue. -
bool pop(Type & result)
Pops an element off the queue, returning it. Returns false if there is nothing left on the queue. -
size_t size()
Returns the current size of the queue (note that since publishers can write to this at any time, this value might not be correct by the end of this call). -
bool empty()
Returns true if this queue is empty, false otherwise (note that since publishers can write to this at any time, this value may not be correct by the time you read it).