| 157 | }; |
| 158 | |
| 159 | class SPSCBoundedQueueBenchmark : public CppBenchmark::BenchmarkPC |
| 160 | { |
| 161 | public: |
| 162 | using BenchmarkPC::BenchmarkPC; |
| 163 | |
| 164 | protected: |
| 165 | void Initialize(CppBenchmark::ContextPC& context) override |
| 166 | { |
| 167 | _queue = std::make_shared<spsc_bounded_queue_t<int>>(queue_bound_size); |
| 168 | _count = 1; |
| 169 | } |
| 170 | |
| 171 | void Cleanup(CppBenchmark::ContextPC& context) override |
| 172 | { |
| 173 | _queue.reset(); |
| 174 | } |
| 175 | |
| 176 | void RunProducer(CppBenchmark::ContextPC& context) override |
| 177 | { |
| 178 | if (_count >= items_to_produce) |
| 179 | { |
| 180 | int value = 0; |
| 181 | if (_queue->enqueue(value)) |
| 182 | context.StopProduce(); |
| 183 | return; |
| 184 | } |
| 185 | |
| 186 | int value = _count; |
| 187 | if (_queue->enqueue(value)) |
| 188 | ++_count; |
| 189 | } |
| 190 | |
| 191 | void RunConsumer(CppBenchmark::ContextPC& context) override |
| 192 | { |
| 193 | int value = -1; |
| 194 | if (_queue->dequeue(value) && (value == 0)) |
| 195 | context.StopConsume(); |
| 196 | } |
| 197 | |
| 198 | private: |
| 199 | std::shared_ptr<spsc_bounded_queue_t<int>> _queue; |
| 200 | std::atomic<int> _count; |
| 201 | }; |
| 202 | |
| 203 | class LockBoundedQueueBenchmark : public CppBenchmark::BenchmarkPC |
| 204 | { |
nothing calls this directly
no outgoing calls
no test coverage detected