| 116 | }; |
| 117 | |
| 118 | class MPMCBoundedQueueBenchmark : public CppBenchmark::BenchmarkPC |
| 119 | { |
| 120 | public: |
| 121 | using BenchmarkPC::BenchmarkPC; |
| 122 | |
| 123 | protected: |
| 124 | void Initialize(CppBenchmark::ContextPC& context) override |
| 125 | { |
| 126 | _queue = std::make_shared<mpmc_bounded_queue_t<int>>(queue_bound_size); |
| 127 | _count = 1; |
| 128 | } |
| 129 | |
| 130 | void Cleanup(CppBenchmark::ContextPC& context) override |
| 131 | { |
| 132 | _queue.reset(); |
| 133 | } |
| 134 | |
| 135 | void RunProducer(CppBenchmark::ContextPC& context) override |
| 136 | { |
| 137 | if (_count >= items_to_produce) |
| 138 | { |
| 139 | int value = 0; |
| 140 | if (_queue->enqueue(value)) |
| 141 | context.StopProduce(); |
| 142 | return; |
| 143 | } |
| 144 | |
| 145 | int value = _count; |
| 146 | if (_queue->enqueue(value)) |
| 147 | ++_count; |
| 148 | } |
| 149 | |
| 150 | void RunConsumer(CppBenchmark::ContextPC& context) override |
| 151 | { |
| 152 | int value = -1; |
| 153 | if (_queue->dequeue(value) && (value == 0)) |
| 154 | context.StopConsume(); |
| 155 | } |
| 156 | |
| 157 | private: |
| 158 | std::shared_ptr<mpmc_bounded_queue_t<int>> _queue; |
| 159 | std::atomic<int> _count; |
| 160 | }; |
| 161 | |
| 162 | class LockBoundedQueueBenchmark : public CppBenchmark::BenchmarkPC |
| 163 | { |
nothing calls this directly
no outgoing calls
no test coverage detected