CppBenchmark 1.0.5.0
C++ Benchmark Library
Loading...
Searching...
No Matches
context_pc.h
Go to the documentation of this file.
1
9#ifndef CPPBENCHMARK_CONTEXT_PC_H
10#define CPPBENCHMARK_CONTEXT_PC_H
11
12#include "benchmark/context.h"
13
14namespace CppBenchmark {
15
17
26class ContextPC : public Context
27{
28 friend class BenchmarkPC;
29
30public:
31 ContextPC() = delete;
32 ContextPC(const ContextPC&) noexcept = default;
33 ContextPC(ContextPC&&) noexcept = default;
34 virtual ~ContextPC() noexcept = default;
35
36 ContextPC& operator=(const ContextPC&) noexcept = default;
37 ContextPC& operator=(ContextPC&&) noexcept = default;
38
40 int producers() const noexcept { return _producers; }
42 int consumers() const noexcept { return _consumers; }
43
45 bool produce_stopped() const noexcept { return *_produce_stopped; }
47 bool consume_stopped() const noexcept { return *_consume_stopped; }
49 void StopProduce() noexcept { *_produce_stopped = true; }
51 void StopConsume() noexcept { *_consume_stopped = true; }
52
54 std::string description() const override;
55
56protected:
62 std::shared_ptr<std::atomic<bool>> _produce_stopped;
64 std::shared_ptr<std::atomic<bool>> _consume_stopped;
65
67
74 ContextPC(int producers, int consumers, int x, int y, int z) noexcept
75 : Context(x, y, z),
78 _produce_stopped(std::make_shared<std::atomic<bool>>(false)),
79 _consume_stopped(std::make_shared<std::atomic<bool>>(false))
80 {}
81};
82
83} // namespace CppBenchmark
84
85#endif // CPPBENCHMARK_CONTEXT_PC_H
Producers/Consumers benchmark base class.
Benchmark running context.
Definition context.h:27
int x() const noexcept
Benchmark first parameter. Valid only if not negative!
Definition context.h:41
int y() const noexcept
Benchmark second parameter. Valid only if not negative!
Definition context.h:43
int z() const noexcept
Benchmark third parameter. Valid only if not negative!
Definition context.h:45
Benchmark producer/consumer running context.
Definition context_pc.h:27
ContextPC(int producers, int consumers, int x, int y, int z) noexcept
Create benchmark running context.
Definition context_pc.h:74
ContextPC(ContextPC &&) noexcept=default
std::shared_ptr< std::atomic< bool > > _produce_stopped
Benchmark produce stopped flag.
Definition context_pc.h:62
bool produce_stopped() const noexcept
Is benchmark produce stopped?
Definition context_pc.h:45
int consumers() const noexcept
Benchmark consumers count.
Definition context_pc.h:42
void StopConsume() noexcept
Stop benchmark consumption.
Definition context_pc.h:51
ContextPC(const ContextPC &) noexcept=default
std::shared_ptr< std::atomic< bool > > _consume_stopped
Benchmark consume stopped flag.
Definition context_pc.h:64
bool consume_stopped() const noexcept
Is benchmark consume stopped?
Definition context_pc.h:47
int _producers
Benchmark producers count.
Definition context_pc.h:58
std::string description() const override
Get description of the current benchmark running context.
void StopProduce() noexcept
Stop benchmark production.
Definition context_pc.h:49
int _consumers
Benchmark consumers count.
Definition context_pc.h:60
int producers() const noexcept
Benchmark producers count.
Definition context_pc.h:40
Benchmark running context definition.
C++ Benchmark project definitions.
Definition barrier.h:15