23#ifndef LIBSEMIGROUPS_RUNNER_HPP_
24#define LIBSEMIGROUPS_RUNNER_HPP_
37#include "detail/fmt.hpp"
38#include "detail/function-ref.hpp"
39#include "detail/report.hpp"
63 [[nodiscard]]
static inline std::chrono::nanoseconds
64 delta(std::chrono::high_resolution_clock::time_point
const& t) {
67 return duration_cast<std::chrono::nanoseconds>(high_resolution_clock::now()
94 using time_point = std::chrono::high_resolution_clock::time_point;
187 _report_time_interval = val;
211 template <
typename Time>
213#pragma GCC diagnostic push
214#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
216#pragma GCC diagnostic pop
231 return _report_time_interval;
260 _start_time = _last_report;
373 if (!_divider.empty()) {
436 detail::FunctionRef<bool(
void)> _stopper;
540 template <
typename Time>
564 template <
typename Func>
571 run_until(detail::FunctionRef<
bool(
void)>(func));
668 [[nodiscard]]
bool dead() const noexcept {
706 LIBSEMIGROUPS_ASSERT(_stopper.valid());
786 virtual void run_impl() = 0;
787 [[nodiscard]]
virtual bool finished_impl()
const = 0;
790 void set_state(
state val)
const noexcept;
Reporter(Reporter &&that)
Default move constructor.
time_point last_report() const noexcept
Get the time point of the last report.
Definition runner.hpp:277
std::string const & report_divider() const noexcept
Get the current divider string for reporting.
Definition runner.hpp:361
bool report() const
Check if it is time to report.
Reporter & operator=(Reporter &&that)
Default move assignment operator.
nanoseconds report_every() const noexcept
Get the minimum elapsed time between reports.
Definition runner.hpp:230
Reporter const & reset_start_time() const
Reset the start time (and last report) to now.
Definition runner.hpp:258
Reporter & report_every(Time t) noexcept
Set the minimum elapsed time between reports in a unit of time other than nanoseconds.
Definition runner.hpp:212
Reporter & init()
Initialize an existing Reporter object.
Reporter & operator=(Reporter const &that)
Default copy assignment operator.
Reporter const & reset_last_report() const
Set the last report time point to now.
Definition runner.hpp:294
std::chrono::high_resolution_clock::time_point time_point
Alias for std::chrono::high_resolution_clock::time_point.
Definition runner.hpp:94
std::string const & report_prefix() const noexcept
Get the current prefix string for reporting.
Definition runner.hpp:328
Reporter & report_prefix(std::string const &val)
Set the prefix string for reporting.
Definition runner.hpp:311
static std::chrono::nanoseconds delta(std::chrono::high_resolution_clock::time_point const &t)
The time between a given point and now.
Definition runner.hpp:64
void emit_divider()
Emits the current divider string for reporting.
Definition runner.hpp:372
Reporter()
Default constructor.
Reporter(Reporter const &that)
Default copy constructor.
std::chrono::nanoseconds nanoseconds
Alias for std::chrono::nanoseconds.
Definition runner.hpp:96
Reporter & report_every(nanoseconds val) noexcept
Set the minimum elapsed time between reports in nanoseconds.
Definition runner.hpp:185
time_point start_time() const noexcept
Get the start time.
Definition runner.hpp:246
Reporter & report_divider(std::string const &val)
Set the divider string for reporting.
Definition runner.hpp:344
void run()
Run until finished.
bool started() const noexcept
Check if run has been called at least once before.
Definition runner.hpp:620
void run_until(Func &&func)
Run until a nullary predicate returns true or finished.
void run_until(bool(*func)())
Run until a nullary predicate returns true or finished.
Definition runner.hpp:570
Runner & operator=(Runner &&other)
Move assignment operator.
void report_why_we_stopped() const
Report why run stopped.
bool stopped() const
Check if the runner is stopped.
Definition runner.hpp:682
bool dead() const noexcept
Check if the runner is dead.
Definition runner.hpp:668
void run_for(Time t)
Run for a specified amount of time.
Definition runner.hpp:541
Runner()
Default constructor.
bool running_until() const noexcept
Check if the runner is currently running until a nullary predicate returns true.
Definition runner.hpp:765
Runner & operator=(Runner const &other)
Copy assignment operator.
virtual bool success() const
Check if run has been run to completion successfully.
Definition runner.hpp:604
Runner(Runner &&other)
Move constructor.
std::chrono::nanoseconds running_for_how_long() const noexcept
Return the last value passed to run_for.
Definition runner.hpp:746
Runner & init()
Initialize an existing Runner object.
bool running() const noexcept
Check if currently running.
Definition runner.hpp:636
bool timed_out() const
Check if the amount of time passed to run_for has elapsed.
Definition runner.hpp:553
void run_for(std::chrono::nanoseconds t)
Run for a specified amount of time.
state
Enum class for the state of the Runner.
Definition runner.hpp:401
@ running_for
Definition runner.hpp:410
@ not_running
Definition runner.hpp:423
@ timed_out
Definition runner.hpp:416
@ stopped_by_predicate
Definition runner.hpp:419
@ running_to_finish
Definition runner.hpp:407
@ never_run
Definition runner.hpp:404
@ running_until
Definition runner.hpp:413
@ dead
Indicates that the Runner was killed (by another thread).
Definition runner.hpp:425
state current_state() const noexcept
Return the current state.
Definition runner.hpp:781
bool running_for() const noexcept
Check if the runner is currently running for a particular length of time.
Definition runner.hpp:728
bool finished() const
Check if run has been run to completion or not.
bool stopped_by_predicate() const
Check if the runner was stopped, or should stop, because of the argument last passed to run_until.
Definition runner.hpp:704
void kill() noexcept
Stop run from running (thread-safe).
Definition runner.hpp:652
Runner(Runner const &other)
Copy constructor.
T duration_cast(T... args)
constexpr std::chrono::nanoseconds FOREVER
Value indicating forever (system dependent but possibly approx. 292 years).
Definition runner.hpp:78
Namespace for everything in the libsemigroups library.
Definition action.hpp:44
void report_no_prefix(std::string_view sv, Args &&... args)
No doc.
Definition report.hpp:181