userver: concurrent::GenericQueue< T, QueuePolicy > Class Template Reference
Loading...
Searching...
No Matches
concurrent::GenericQueue< T, QueuePolicy > Class Template Referencefinal

#include <userver/concurrent/queue.hpp>

Detailed Description

template<typename T, typename QueuePolicy>
class concurrent::GenericQueue< T, QueuePolicy >

Queue with single and multi producer/consumer options.

Template Parameters
Telement type
QueuePolicypolicy type, see DefaultQueuePolicy for details

On practice, instead of using GenericQueue directly, use an alias:

See also
concurrent_queues
Examples
samples/tcp_full_duplex_service/tcp_full_duplex_service.cpp.

Definition at line 122 of file queue.hpp.

+ Inheritance diagram for concurrent::GenericQueue< T, QueuePolicy >:

Classes

class  MultiConsumerSide
 
class  MultiProducerSide
 
class  NoMaxSizeProducerSide
 
class  SingleConsumerSide
 
class  SingleProducerSide
 

Public Types

using ValueType = T
 
using Producer = concurrent::Producer<GenericQueue, ProducerToken, EmplaceEnabler>
 
using Consumer = concurrent::Consumer<GenericQueue, ConsumerToken, EmplaceEnabler>
 
using MultiProducer = concurrent::Producer<GenericQueue, MultiProducerToken, EmplaceEnabler>
 
using MultiConsumer = concurrent::Consumer<GenericQueue, MultiConsumerToken, EmplaceEnabler>
 

Public Member Functions

Producer GetProducer ()
 
MultiProducer GetMultiProducer ()
 
Consumer GetConsumer ()
 
MultiConsumer GetMultiConsumer ()
 
void SetSoftMaxSize (std::size_t max_size)
 Sets the limit on the queue size, pushes over this limit will block.
 
std::size_t GetSoftMaxSize () const
 Gets the limit on the queue size.
 
std::size_t GetSizeApproximate () const
 Gets the approximate size of queue.
 

Static Public Member Functions

static std::shared_ptr< GenericQueueCreate (std::size_t max_size=kUnbounded)
 Create a new queue.
 

Static Public Attributes

static constexpr std::size_t kUnbounded = std::numeric_limits<std::size_t>::max() / 4
 

Member Typedef Documentation

◆ Consumer

template<typename T , typename QueuePolicy >
using concurrent::GenericQueue< T, QueuePolicy >::Consumer = concurrent::Consumer<GenericQueue, ConsumerToken, EmplaceEnabler>

Definition at line 154 of file queue.hpp.

◆ MultiConsumer

template<typename T , typename QueuePolicy >
using concurrent::GenericQueue< T, QueuePolicy >::MultiConsumer = concurrent::Consumer<GenericQueue, MultiConsumerToken, EmplaceEnabler>

Definition at line 156 of file queue.hpp.

◆ MultiProducer

template<typename T , typename QueuePolicy >
using concurrent::GenericQueue< T, QueuePolicy >::MultiProducer = concurrent::Producer<GenericQueue, MultiProducerToken, EmplaceEnabler>

Definition at line 155 of file queue.hpp.

◆ Producer

template<typename T , typename QueuePolicy >
using concurrent::GenericQueue< T, QueuePolicy >::Producer = concurrent::Producer<GenericQueue, ProducerToken, EmplaceEnabler>

Definition at line 153 of file queue.hpp.

◆ ValueType

template<typename T , typename QueuePolicy >
using concurrent::GenericQueue< T, QueuePolicy >::ValueType = T

Definition at line 151 of file queue.hpp.

Member Function Documentation

◆ Create()

template<typename T , typename QueuePolicy >
static std::shared_ptr< GenericQueue > concurrent::GenericQueue< T, QueuePolicy >::Create ( std::size_t max_size = kUnbounded)
inlinestatic

Create a new queue.

Definition at line 191 of file queue.hpp.

◆ GetConsumer()

template<typename T , typename QueuePolicy >
Consumer concurrent::GenericQueue< T, QueuePolicy >::GetConsumer ( )
inline

Get a Consumer which makes it possible to read items from the queue. Can be called multiple times. The resulting Consumer is not thread-safe, so you have to use multiple Consumers of the same queue to simultaneously write from multiple coroutines/threads.

Note
Consumer may outlive the queue and producers.

Definition at line 227 of file queue.hpp.

◆ GetMultiConsumer()

template<typename T , typename QueuePolicy >
MultiConsumer concurrent::GenericQueue< T, QueuePolicy >::GetMultiConsumer ( )
inline

Get a MultiConsumer which makes it possible to read items from the queue. Can be called multiple times. The resulting MultiConsumer is thread-safe, so it can be used simultaneously from multiple coroutines/threads.

Note
MultiConsumer may outlive the queue and producers.
Prefer Consumer tokens when possible, because MultiConsumer token incurs some overhead.

Definition at line 241 of file queue.hpp.

◆ GetMultiProducer()

template<typename T , typename QueuePolicy >
MultiProducer concurrent::GenericQueue< T, QueuePolicy >::GetMultiProducer ( )
inline

Get a MultiProducer which makes it possible to push items into the queue. Can be called multiple times. The resulting MultiProducer is thread-safe, so it can be used simultaneously from multiple coroutines/threads.

Note
MultiProducer may outlive the queue and consumers.
Prefer Producer tokens when possible, because MultiProducer token incurs some overhead.

Definition at line 215 of file queue.hpp.

◆ GetProducer()

template<typename T , typename QueuePolicy >
Producer concurrent::GenericQueue< T, QueuePolicy >::GetProducer ( )
inline

Get a Producer which makes it possible to push items into the queue. Can be called multiple times. The resulting Producer is not thread-safe, so you have to use multiple Producers of the same queue to simultaneously write from multiple coroutines/threads.

Note
Producer may outlive the queue and consumers.

Definition at line 201 of file queue.hpp.

◆ GetSizeApproximate()

template<typename T , typename QueuePolicy >
std::size_t concurrent::GenericQueue< T, QueuePolicy >::GetSizeApproximate ( ) const
inline

Gets the approximate size of queue.

Definition at line 255 of file queue.hpp.

◆ GetSoftMaxSize()

template<typename T , typename QueuePolicy >
std::size_t concurrent::GenericQueue< T, QueuePolicy >::GetSoftMaxSize ( ) const
inline

Gets the limit on the queue size.

Definition at line 252 of file queue.hpp.

◆ SetSoftMaxSize()

template<typename T , typename QueuePolicy >
void concurrent::GenericQueue< T, QueuePolicy >::SetSoftMaxSize ( std::size_t max_size)
inline

Sets the limit on the queue size, pushes over this limit will block.

Note
This is a soft limit and may be slightly overrun under load.

Definition at line 249 of file queue.hpp.

Friends And Related Symbol Documentation

◆ Consumer< GenericQueue, ConsumerToken, EmplaceEnabler >

template<typename T , typename QueuePolicy >
friend class Consumer< GenericQueue, ConsumerToken, EmplaceEnabler >
friend

Definition at line 133 of file queue.hpp.

◆ Consumer< GenericQueue, MultiConsumerToken, EmplaceEnabler >

template<typename T , typename QueuePolicy >
friend class Consumer< GenericQueue, MultiConsumerToken, EmplaceEnabler >
friend

Definition at line 133 of file queue.hpp.

◆ Producer< GenericQueue, MultiProducerToken, EmplaceEnabler >

template<typename T , typename QueuePolicy >
friend class Producer< GenericQueue, MultiProducerToken, EmplaceEnabler >
friend

Definition at line 133 of file queue.hpp.

◆ Producer< GenericQueue, ProducerToken, EmplaceEnabler >

template<typename T , typename QueuePolicy >
friend class Producer< GenericQueue, ProducerToken, EmplaceEnabler >
friend

Definition at line 133 of file queue.hpp.

Member Data Documentation

◆ kUnbounded

template<typename T , typename QueuePolicy >
constexpr std::size_t concurrent::GenericQueue< T, QueuePolicy >::kUnbounded = std::numeric_limits<std::size_t>::max() / 4
staticconstexpr

Definition at line 158 of file queue.hpp.


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