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
24#include <functional>
25#include <thread>
26
27namespace toolbox {
28inline namespace io {
29class Reactor;
30
31using HistogramPtr = std::unique_ptr<Histogram>;
32
35 = std::function<void(CyclTime now, HistogramPtr&& time_hist, HistogramPtr&& work_hist)>;
37using LoopCallbackFunction = std::function<void(CyclTime now)>;
38
40 public:
51 ReactorRunner(Reactor& r, long busy_cycles, ThreadConfig config);
52
64 ReactorRunner(Reactor& r, long busy_cycles, ThreadConfig config,
65 MetricCallbackFunction metric_cb);
66
79 ReactorRunner(Reactor& r, long busy_cycles, ThreadConfig config,
81
83
84 // Copy.
85 ReactorRunner(const ReactorRunner&) = delete;
87
88 // Move.
91
92 private:
93 Reactor& reactor_;
94 std::atomic<bool> stop_{false};
95 std::thread thread_;
96};
97
98} // namespace io
99} // namespace toolbox
100
101#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)> LoopCallbackFunction
LoopCallbackFunction called at end of each Reactor loop, indicating micros taken and work done.
Definition Runner.hpp:37
std::function< void(CyclTime now, HistogramPtr &&time_hist, HistogramPtr &&work_hist)> MetricCallbackFunction
MetricCallbackFunction implementer is responsible for deleting the Histogram.
Definition Runner.hpp:35
std::unique_ptr< Histogram > HistogramPtr
Definition Runner.hpp:31
constexpr auto bind() noexcept
Definition Slot.hpp:92
ThreadConfig holds the thread attributes.
Definition Thread.hpp:29