Toolbox
snapshot
The Reactive C++ Toolbox
Loading...
Searching...
No Matches
toolbox
io
Runner.hpp
Go to the documentation of this file.
1
// The Reactive C++ Toolbox.
2
// Copyright (C) 2013-2019 Swirly Cloud Limited
3
// Copyright (C) 2022 Reactive Markets Limited
4
//
5
// Licensed under the Apache License, Version 2.0 (the "License");
6
// you may not use this file except in compliance with the License.
7
// You may obtain a copy of the License at
8
//
9
// http://www.apache.org/licenses/LICENSE-2.0
10
//
11
// Unless required by applicable law or agreed to in writing, software
12
// distributed under the License is distributed on an "AS IS" BASIS,
13
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
// See the License for the specific language governing permissions and
15
// limitations under the License.
16
17
#ifndef TOOLBOX_IO_RUNNER_HPP
18
#define TOOLBOX_IO_RUNNER_HPP
19
20
#include <
toolbox/hdr/Histogram.hpp
>
21
#include <
toolbox/sys/Thread.hpp
>
22
#include <
toolbox/sys/Time.hpp
>
23
#include <
toolbox/util/Slot.hpp
>
24
25
#include <functional>
26
#include <thread>
27
28
namespace
toolbox
{
29
inline
namespace
io {
30
class
Reactor;
31
32
using
HistogramPtr
= std::unique_ptr<Histogram>;
33
35
using
MetricCallbackFunction
36
= std::function<
void
(
CyclTime
now,
HistogramPtr
&&
time_hist
,
HistogramPtr
&&
work_hist
)>;
37
39
struct
PassInfo
{
40
WallTime
start
{};
41
Nanos
duration
{};
42
int
work
{0};
43
};
44
46
using
PassSlot
=
BasicSlot
<
void
(
const
PassInfo
&)>;
47
48
class
TOOLBOX_API
ReactorRunner
{
49
public
:
60
ReactorRunner
(
Reactor
& r,
long
busy_cycles,
ThreadConfig
config);
61
73
ReactorRunner
(
Reactor
& r,
long
busy_cycles,
ThreadConfig
config,
74
MetricCallbackFunction
metric_cb);
75
88
ReactorRunner
(
Reactor
& r,
long
busy_cycles,
ThreadConfig
config,
89
MetricCallbackFunction
metric_cb,
PassSlot
pass_slot);
90
91
~ReactorRunner
();
92
93
// Copy.
94
ReactorRunner
(
const
ReactorRunner
&) =
delete
;
95
ReactorRunner
&
operator=
(
const
ReactorRunner
&) =
delete
;
96
97
// Move.
98
ReactorRunner
(
ReactorRunner
&&) =
delete
;
99
ReactorRunner
&
operator=
(
ReactorRunner
&&) =
delete
;
100
101
private
:
102
Reactor
& reactor_;
103
std::atomic<bool> stop_{
false
};
104
std::thread thread_;
105
};
106
107
}
// namespace io
108
}
// namespace toolbox
109
110
#endif
// TOOLBOX_IO_RUNNER_HPP
TOOLBOX_API
#define TOOLBOX_API
Definition
Config.h:39
Histogram.hpp
Slot.hpp
Thread.hpp
Time.hpp
toolbox::io::ReactorRunner
Definition
Runner.hpp:48
toolbox::io::ReactorRunner::operator=
ReactorRunner & operator=(const ReactorRunner &)=delete
toolbox::io::ReactorRunner::ReactorRunner
ReactorRunner(ReactorRunner &&)=delete
toolbox::io::ReactorRunner::operator=
ReactorRunner & operator=(ReactorRunner &&)=delete
toolbox::io::ReactorRunner::ReactorRunner
ReactorRunner(const ReactorRunner &)=delete
toolbox::io::Reactor
Definition
Reactor.hpp:34
toolbox::CyclTime
Definition
Time.hpp:125
toolbox::BasicSlot
Definition
Slot.hpp:26
toolbox::io::MetricCallbackFunction
std::function< void(CyclTime now, HistogramPtr &&time_hist, HistogramPtr &&work_hist)> MetricCallbackFunction
MetricCallbackFunction implementer is responsible for deleting the Histogram.
Definition
Runner.hpp:36
toolbox::io::HistogramPtr
std::unique_ptr< Histogram > HistogramPtr
Definition
Runner.hpp:32
toolbox::sys::WallTime
WallClock::time_point WallTime
Definition
Time.hpp:113
toolbox::sys::Nanos
std::chrono::nanoseconds Nanos
Definition
Time.hpp:39
toolbox::util::bind
constexpr auto bind() noexcept
Definition
Slot.hpp:97
toolbox
Definition
Benchmark.cpp:27
toolbox::io::PassInfo
One iteration of a runner's loop.
Definition
Runner.hpp:39
toolbox::io::PassInfo::work
int work
Definition
Runner.hpp:42
toolbox::io::PassInfo::start
WallTime start
Definition
Runner.hpp:40
toolbox::io::PassInfo::duration
Nanos duration
Definition
Runner.hpp:41
toolbox::ThreadConfig
ThreadConfig holds the thread attributes.
Definition
Thread.hpp:30
Generated by
1.9.8