userver: userver/concurrent/queue_fwd.hpp Source File
Loading...
Searching...
No Matches
queue_fwd.hpp
Go to the documentation of this file.
1#pragma once
2
3/// @file userver/concurrent/queue_fwd.hpp
4/// @brief Forward declarations for @ref concurrent::GenericQueue and its queue aliases.
5
6#include <string>
7
8USERVER_NAMESPACE_BEGIN
9
10namespace concurrent {
11
12namespace impl {
13
14struct NoToken;
15
16template <typename Queue>
17class QueueEmplaceEnabler;
18
19template <bool MultipleProducer, bool MultipleConsumer>
20struct SimpleQueuePolicy;
21
22template <bool MultipleProducer, bool MultipleConsumer>
23struct NoMaxSizeQueuePolicy;
24
25template <bool MultipleProducer, bool MultipleConsumer>
26struct ContainerQueuePolicy;
27
28} // namespace impl
29
30template <typename T, typename QueuePolicy>
31class GenericQueue;
32
33template <typename QueueType, typename ConsumerToken, typename EmplaceEnablerType>
34class Consumer;
35
36/// @ingroup userver_concurrency
37///
38/// @brief Non FIFO multiple producers multiple consumers queue.
39///
40/// Items from the same producer are always delivered in the production order.
41/// Items from different producers (or when using a `MultiProducer` token) are
42/// delivered in an unspecified order. In other words, FIFO order is maintained
43/// only within producers, but not between them. This may lead to increased peak
44/// latency of item processing.
45///
46/// In exchange for this, the queue has lower contention and increased
47/// throughput compared to a conventional lock-free queue.
48///
49/// @see @ref scripts/docs/en/userver/synchronization.md
50template <typename T>
51using NonFifoMpmcQueue = GenericQueue<T, impl::SimpleQueuePolicy<true, true>>;
52
53/// @ingroup userver_concurrency
54///
55/// @brief Non FIFO multiple producers single consumer queue.
56///
57/// @see @ref concurrent::NonFifoMpmcQueue for the description of what NonFifo means.
58/// @see @ref scripts/docs/en/userver/synchronization.md
59template <typename T>
60using NonFifoMpscQueue = GenericQueue<T, impl::SimpleQueuePolicy<true, false>>;
61
62/// @ingroup userver_concurrency
63///
64/// @brief Single producer multiple consumers queue.
65///
66/// @see @ref scripts/docs/en/userver/synchronization.md
67template <typename T>
68using SpmcQueue = GenericQueue<T, impl::SimpleQueuePolicy<false, true>>;
69
70/// @ingroup userver_concurrency
71///
72/// @brief Single producer single consumer queue.
73///
74/// @see @ref scripts/docs/en/userver/synchronization.md
75template <typename T>
76using SpscQueue = GenericQueue<T, impl::SimpleQueuePolicy<false, false>>;
77
78/// @ingroup userver_concurrency
79///
80/// @brief Like @ref concurrent::NonFifoMpscQueue, but does not support setting max size and is thus slightly faster.
81///
82/// @see @ref scripts/docs/en/userver/synchronization.md
83template <typename T>
84using UnboundedNonFifoMpscQueue = GenericQueue<T, impl::NoMaxSizeQueuePolicy<true, false>>;
85
86/// @ingroup userver_concurrency
87///
88/// @brief Like @ref concurrent::SpmcQueue, but does not support setting max size and is thus slightly faster.
89///
90/// @see @ref scripts/docs/en/userver/synchronization.md
91template <typename T>
92using UnboundedSpmcQueue = GenericQueue<T, impl::NoMaxSizeQueuePolicy<false, true>>;
93
94/// @ingroup userver_concurrency
95///
96/// @brief Like @ref concurrent::SpscQueue, but does not support setting max size and is thus slightly faster.
97///
98/// @see @ref scripts/docs/en/userver/synchronization.md
99template <typename T>
100using UnboundedSpscQueue = GenericQueue<T, impl::NoMaxSizeQueuePolicy<false, false>>;
101
102/// @ingroup userver_concurrency
103///
104/// @brief Single producer single consumer queue of std::string which is bounded by the total bytes inside the strings.
105///
106/// @see @ref scripts/docs/en/userver/synchronization.md
107using StringStreamQueue = GenericQueue<std::string, impl::ContainerQueuePolicy<false, false>>;
108
109/// @brief Consumer of @ref concurrent::StringStreamQueue.
111 Consumer<StringStreamQueue, impl::NoToken, impl::QueueEmplaceEnabler<StringStreamQueue>>;
112
113} // namespace concurrent
114
115USERVER_NAMESPACE_END