Toolbox snapshot
The Reactive C++ Toolbox
Loading...
Searching...
No Matches
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
22#include <toolbox/sys/Time.hpp>
23#include <toolbox/util/Slot.hpp>
24
25#include <functional>
26#include <thread>
27
28namespace toolbox {
29inline namespace io {
30class Reactor;
31
32using HistogramPtr = std::unique_ptr<Histogram>;
33
36 = std::function<void(CyclTime now, HistogramPtr&& time_hist, HistogramPtr&& work_hist)>;
37
39struct PassInfo {
42 int work{0};
43};
44
47
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
92
93 // Copy.
94 ReactorRunner(const ReactorRunner&) = delete;
96
97 // Move.
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
#define TOOLBOX_API
Definition Config.h:39
ReactorRunner & operator=(const ReactorRunner &)=delete
ReactorRunner(ReactorRunner &&)=delete
ReactorRunner & operator=(ReactorRunner &&)=delete
ReactorRunner(const ReactorRunner &)=delete
std::function< void(CyclTime now, HistogramPtr &&time_hist, HistogramPtr &&work_hist)> MetricCallbackFunction
MetricCallbackFunction implementer is responsible for deleting the Histogram.
Definition Runner.hpp:36
std::unique_ptr< Histogram > HistogramPtr
Definition Runner.hpp:32
WallClock::time_point WallTime
Definition Time.hpp:113
std::chrono::nanoseconds Nanos
Definition Time.hpp:39
constexpr auto bind() noexcept
Definition Slot.hpp:97
One iteration of a runner's loop.
Definition Runner.hpp:39
ThreadConfig holds the thread attributes.
Definition Thread.hpp:30