diff --git a/examples/count/main.cc b/examples/count/main.cc index e0c6e92b..0b1e51f0 100644 --- a/examples/count/main.cc +++ b/examples/count/main.cc @@ -5,7 +5,7 @@ using namespace reactor; using namespace std::chrono_literals; -class Count : public Reactor { +class Count final : public Reactor { private: // actions Timer timer{"timer", this}; diff --git a/examples/hello/main.cc b/examples/hello/main.cc index 3b02fd89..2f6c88f8 100644 --- a/examples/hello/main.cc +++ b/examples/hello/main.cc @@ -6,7 +6,7 @@ using namespace reactor; using namespace std::chrono_literals; -class Hello : public Reactor { +class Hello final : public Reactor { private: // actions Timer timer{"timer", this, 1s, 2s}; diff --git a/examples/multiport_mutation/consumer.hh b/examples/multiport_mutation/consumer.hh index 17b89b8f..97fc2d12 100644 --- a/examples/multiport_mutation/consumer.hh +++ b/examples/multiport_mutation/consumer.hh @@ -6,8 +6,8 @@ * Tassilo Tanneberger */ -#ifndef CONSUMER_HH // NOLINT -#define CONSUMER_HH // NOLINT +#ifndef MULTIPORT_MUTATION_CONSUMER_HH +#define MULTIPORT_MUTATION_CONSUMER_HH #include #include @@ -45,4 +45,4 @@ public: void assemble() override { handle.declare_trigger(&in); } }; -#endif // CONSUMER_HH +#endif // MULTIPORT_MUTATION_CONSUMER_HH diff --git a/examples/multiport_mutation/load_balancer.hh b/examples/multiport_mutation/load_balancer.hh index d96f6ed7..eaeb6375 100644 --- a/examples/multiport_mutation/load_balancer.hh +++ b/examples/multiport_mutation/load_balancer.hh @@ -6,8 +6,8 @@ * Tassilo Tanneberger */ -#ifndef MULTIPORT_MUTATION_LOAD_BALANCER_HH // NOLINT -#define MULTIPORT_MUTATION_LOAD_BALANCER_HH // NOLINT +#ifndef MULTIPORT_MUTATION_LOAD_BALANCER_HH +#define MULTIPORT_MUTATION_LOAD_BALANCER_HH #include #include diff --git a/examples/multiport_mutation/main.cc b/examples/multiport_mutation/main.cc index 25ff0578..c006ec55 100644 --- a/examples/multiport_mutation/main.cc +++ b/examples/multiport_mutation/main.cc @@ -29,7 +29,7 @@ class Deployment final : public Reactor { // NOLINT int state = 0; public: - Inner(Reactor* reactor) + explicit Inner(Reactor* reactor) : MutableScope(reactor) {} void reaction_1(const Input& scale, std::vector>& reactor_bank, ModifableMultiport>& load_balancer) { @@ -41,8 +41,8 @@ class Deployment final : public Reactor { // NOLINT }; std::function get_input_port = [](const std::unique_ptr& consumer) { return &consumer->in; }; - auto rescale = std::make_shared>(&load_balancer, &reactor_bank, - get_input_port, lambda, new_size); + const auto rescale = std::make_shared>( + &load_balancer, &reactor_bank, get_input_port, lambda, new_size); add_to_transaction(rescale); diff --git a/examples/multiport_mutation/producer.hh b/examples/multiport_mutation/producer.hh index 4348afb9..914b7edf 100644 --- a/examples/multiport_mutation/producer.hh +++ b/examples/multiport_mutation/producer.hh @@ -6,8 +6,8 @@ * Tassilo Tanneberger */ -#ifndef MULTIPORT_MUTATION_PRODUCER_HH // NOLINT -#define MULTIPORT_MUTATION_PRODUCER_HH // NOLINT +#ifndef MULTIPORT_MUTATION_PRODUCER_HH +#define MULTIPORT_MUTATION_PRODUCER_HH #include diff --git a/examples/ports/main.cc b/examples/ports/main.cc index 671d89b7..6f16389f 100644 --- a/examples/ports/main.cc +++ b/examples/ports/main.cc @@ -5,7 +5,7 @@ using namespace reactor; using namespace std::chrono_literals; -class Trigger : public Reactor { +class Trigger final : public Reactor { private: Timer timer; Reaction r_timer{"r_timer", 1, this, [this]() { on_timer(); }}; @@ -25,7 +25,7 @@ class Trigger : public Reactor { void on_timer() { trigger.set(); } }; -class Counter : public Reactor { +class Counter final : public Reactor { private: int value_{0}; Reaction r_trigger{"r_trigger", 1, this, [this]() { on_trigger(); }}; @@ -49,7 +49,7 @@ class Counter : public Reactor { } }; -class Printer : public Reactor { +class Printer final : public Reactor { private: Reaction r_value{"r_value", 1, this, [this]() { on_value(); }}; @@ -64,10 +64,10 @@ class Printer : public Reactor { r_value.declare_trigger(&value); } - void on_value() { std::cout << this->name() << ": " << *value.get() << '\n'; } + void on_value() const { std::cout << this->name() << ": " << *value.get() << '\n'; } }; -class Adder : public Reactor { +class Adder final : public Reactor { private: Reaction r_add{"r_add", 1, this, [this]() { add(); }}; diff --git a/examples/power_train/main.cc b/examples/power_train/main.cc index 05efe57f..7badae84 100644 --- a/examples/power_train/main.cc +++ b/examples/power_train/main.cc @@ -4,7 +4,7 @@ using namespace reactor; -class LeftPedal : public Reactor { +class LeftPedal final : public Reactor { public: // ports Output angle{"angle", this}; // NOLINT @@ -30,7 +30,7 @@ class LeftPedal : public Reactor { } }; -class RightPedal : public Reactor { +class RightPedal final : public Reactor { public: // ports Output angle{"angle", this}; // NOLINT @@ -60,7 +60,7 @@ class RightPedal : public Reactor { } }; -class BrakeControl : public Reactor { +class BrakeControl final : public Reactor { public: // ports Input angle{"angle", this}; // NOLINT @@ -81,7 +81,7 @@ class BrakeControl : public Reactor { } }; -class EngineControl : public Reactor { +class EngineControl final : public Reactor { public: // ports Input angle{"angle", this}; // NOLINT @@ -118,7 +118,7 @@ class EngineControl : public Reactor { } }; -class Brake : public Reactor { +class Brake final : public Reactor { public: // ports Input force{"force", this}; // NOLINT @@ -136,7 +136,7 @@ class Brake : public Reactor { void assemble() override { r1.declare_trigger(&force); } }; -class Engine : public Reactor { +class Engine final : public Reactor { public: // ports Input torque{"torque", this}; // NOLINT diff --git a/include/reactor-cpp/assert.hh b/include/reactor-cpp/assert.hh index 339eee8b..4dc7fa72 100644 --- a/include/reactor-cpp/assert.hh +++ b/include/reactor-cpp/assert.hh @@ -13,7 +13,6 @@ #include "reactor-cpp/fwd.hh" #include -#include #include #include @@ -71,7 +70,7 @@ public: : std::runtime_error(build_message(msg)) {} }; -constexpr void validate([[maybe_unused]] bool condition, [[maybe_unused]] const std::string_view message) { +constexpr void validate([[maybe_unused]] const bool condition, [[maybe_unused]] const std::string_view message) { if constexpr (runtime_validation) { if (!condition) { print_backtrace(); @@ -80,8 +79,8 @@ constexpr void validate([[maybe_unused]] bool condition, [[maybe_unused]] const } } -template constexpr auto extract_value(E enum_value) -> typename std::underlying_type_t { - return static_cast>(enum_value); +template constexpr auto extract_value(E enum_value) -> std::underlying_type_t { + return static_cast>(enum_value); } void assert_phase([[maybe_unused]] const ReactorElement* ptr, [[maybe_unused]] Phase phase); diff --git a/include/reactor-cpp/connection.hh b/include/reactor-cpp/connection.hh index 106738fc..f58e0f3d 100644 --- a/include/reactor-cpp/connection.hh +++ b/include/reactor-cpp/connection.hh @@ -17,7 +17,6 @@ #include "logical_time.hh" #include "port.hh" #include "reaction.hh" -#include "reactor.hh" #include "time.hh" #include "time_barrier.hh" @@ -69,7 +68,7 @@ protected: return [this](const BasePort& port) { // We know that port must be of type Port auto& typed_port = reinterpret_cast&>(port); // NOLINT(cppcoreguidelines-pro-type-reinterpret-cast) - if constexpr (std::is_same::value) { + if constexpr (std::is_same_v) { this->schedule(); } else { this->schedule(std::move(typed_port.get())); @@ -81,7 +80,7 @@ public: void setup() noexcept override { Action::setup(); - if constexpr (std::is_same::value) { + if constexpr (std::is_same_v) { for (auto port : this->downstream_ports()) { port->set(); } @@ -134,7 +133,7 @@ public: // without locking. auto tag = Tag::from_logical_time(scheduler->logical_time()); [[maybe_unused]] bool result{false}; - if constexpr (std::is_same::value) { + if constexpr (std::is_same_v) { result = this->schedule_at(tag); } else { result = this->schedule_at(std::move(typed_port.get()), tag); diff --git a/include/reactor-cpp/logging.hh b/include/reactor-cpp/logging.hh index 4ba08434..8b661338 100644 --- a/include/reactor-cpp/logging.hh +++ b/include/reactor-cpp/logging.hh @@ -10,13 +10,11 @@ #define REACTOR_CPP_LOGGING_HH #include "reactor-cpp/config.hh" -#include "reactor-cpp/time.hh" -#include + #include #include #include #include -#include namespace reactor::log { diff --git a/include/reactor-cpp/multiport.hh b/include/reactor-cpp/multiport.hh index b0a6704d..2cf11dfa 100644 --- a/include/reactor-cpp/multiport.hh +++ b/include/reactor-cpp/multiport.hh @@ -24,8 +24,8 @@ namespace reactor { class BaseMultiport { // NOLINT cppcoreguidelines-special-member-functions,-warnings-as-errors protected: - std::atomic size_{0}; - std::vector present_ports_{}; + std::atomic size_{0}; // NOLINT cppcoreguidelines-non-private-member-variables-in-classes + std::vector present_ports_{}; // NOLINT cppcoreguidelines-non-private-member-variables-in-classes private: std::string name_{}; @@ -53,11 +53,11 @@ protected: public: BaseMultiport(std::string name, Reactor* container) : name_(std::move(name)) - , container_(container) {}; + , container_(container) {} ~BaseMultiport() = default; [[nodiscard]] auto name() const noexcept -> const std::string& { return name_; } - auto container() const noexcept -> Reactor* { return container_; } + [[nodiscard]] auto container() const noexcept -> Reactor* { return container_; } }; template > diff --git a/include/reactor-cpp/mutations/multiport.hh b/include/reactor-cpp/mutations/multiport.hh index 503dcff3..f90b5298 100644 --- a/include/reactor-cpp/mutations/multiport.hh +++ b/include/reactor-cpp/mutations/multiport.hh @@ -9,8 +9,6 @@ #ifndef REACTOR_CPP_MUTATIONS_MULTIPORT_HH #define REACTOR_CPP_MUTATIONS_MULTIPORT_HH -#include - #include "../multiport.hh" #include "../mutations.hh" #include "../port.hh" diff --git a/include/reactor-cpp/reaction.hh b/include/reactor-cpp/reaction.hh index 84b8e539..37e7864e 100644 --- a/include/reactor-cpp/reaction.hh +++ b/include/reactor-cpp/reaction.hh @@ -61,7 +61,7 @@ public: void startup() final {} void shutdown() final {} - void trigger(); + void trigger() const; void set_index(unsigned index); template void set_deadline(Dur deadline, const std::function& handler) { diff --git a/include/reactor-cpp/reactor.hh b/include/reactor-cpp/reactor.hh index 8f1635bb..10d055d0 100644 --- a/include/reactor-cpp/reactor.hh +++ b/include/reactor-cpp/reactor.hh @@ -10,7 +10,6 @@ #define REACTOR_CPP_REACTOR_HH #include -#include #include #include "action.hh" diff --git a/include/reactor-cpp/reactor_element.hh b/include/reactor-cpp/reactor_element.hh index 837b5d31..5e05eb4b 100644 --- a/include/reactor-cpp/reactor_element.hh +++ b/include/reactor-cpp/reactor_element.hh @@ -11,8 +11,6 @@ #define REACTOR_CPP_REACTOR_ELEMENT_HH #include -#include -#include #include #include diff --git a/include/reactor-cpp/semaphore.hh b/include/reactor-cpp/semaphore.hh index bc198547..d4330696 100644 --- a/include/reactor-cpp/semaphore.hh +++ b/include/reactor-cpp/semaphore.hh @@ -9,7 +9,6 @@ #ifndef REACTOR_CPP_SEMAPHORE_HH #define REACTOR_CPP_SEMAPHORE_HH -#include #include #include diff --git a/include/reactor-cpp/statistics.hh b/include/reactor-cpp/statistics.hh index 76a91562..19875ac9 100644 --- a/include/reactor-cpp/statistics.hh +++ b/include/reactor-cpp/statistics.hh @@ -11,7 +11,6 @@ #include -#include "reactor-cpp/config.hh" #include "reactor-cpp/logging.hh" namespace reactor { @@ -23,7 +22,7 @@ private: #else constexpr static bool enabled_{false}; #endif - // NOLINTBEGIN(cppcoreguidelines-avoid-non-const-global-variables) + // NOLINT BEGIN(cppcoreguidelines-avoid-non-const-global-variables) inline static std::atomic_size_t reactor_instances_{0}; inline static std::atomic_size_t connections_{0}; inline static std::atomic_size_t reactions_{0}; @@ -34,7 +33,7 @@ private: inline static std::atomic_size_t triggered_actions_{0}; inline static std::atomic_size_t set_ports_{0}; inline static std::atomic_size_t scheduled_actions_{0}; - // NOLINTEND(cppcoreguidelines-avoid-non-const-global-variables) + // NOLINT END(cppcoreguidelines-avoid-non-const-global-variables) static void increment(std::atomic_size_t& counter) { if constexpr (enabled_) { diff --git a/include/reactor-cpp/time_barrier.hh b/include/reactor-cpp/time_barrier.hh index a5874106..bafa132c 100644 --- a/include/reactor-cpp/time_barrier.hh +++ b/include/reactor-cpp/time_barrier.hh @@ -9,7 +9,6 @@ #ifndef REACTOR_CPP_TIME_BARRIER_HH #define REACTOR_CPP_TIME_BARRIER_HH -#include "fwd.hh" #include "logical_time.hh" #include "scheduler.hh" #include "time.hh" diff --git a/include/reactor-cpp/value_ptr.hh b/include/reactor-cpp/value_ptr.hh index a6d55089..47199e1e 100644 --- a/include/reactor-cpp/value_ptr.hh +++ b/include/reactor-cpp/value_ptr.hh @@ -18,8 +18,6 @@ #include #include -#include "reactor-cpp/logging.hh" - namespace reactor { namespace detail { @@ -459,8 +457,7 @@ public: // get_mutable_copy() friend class ImmutableValuePtr; - // Give the factory function make_mutable_value() access to the private - // constructor + // Give the factory function make_mutable_value() access to the private constructor template friend auto reactor::make_mutable_value(Args&&... args) -> reactor::MutableValuePtr; }; @@ -468,7 +465,7 @@ public: template class ImmutableValuePtr { public: /// A type alias that adds ``const`` to ``T`` - using const_T = typename std::add_const_t; + using const_T = std::add_const_t; private: T value_{}; diff --git a/lib/action.cc b/lib/action.cc index 04a52a41..ac18cb02 100644 --- a/lib/action.cc +++ b/lib/action.cc @@ -15,7 +15,7 @@ namespace reactor { -BaseAction::BaseAction(const std::string& name, Environment* environment, bool logical, Duration min_delay) +BaseAction::BaseAction(const std::string& name, Environment* environment, const bool logical, const Duration min_delay) : ReactorElement(name, ReactorElement::Type::Action, environment) , min_delay_(min_delay) , logical_(logical) { @@ -27,9 +27,8 @@ void BaseAction::register_trigger(Reaction* reaction) { reactor_assert(this->environment() == reaction->environment()); assert_phase(this, Phase::Assembly); validate(this->container() == reaction->container(), - "Action triggers must belong to the same reactor as the triggered " - "reaction"); - [[maybe_unused]] bool result = triggers_.insert(reaction).second; + "Action triggers must belong to the same reactor as the triggered reaction"); + [[maybe_unused]] const bool result = triggers_.insert(reaction).second; reactor_assert(result); } @@ -40,7 +39,7 @@ void BaseAction::register_scheduler(Reaction* reaction) { // the reaction must belong to the same reactor as this action validate(this->container() == reaction->container(), "Scheduable actions must belong to the same reactor as the " "triggered reaction"); - [[maybe_unused]] bool result = schedulers_.insert(reaction).second; + [[maybe_unused]] const bool result = schedulers_.insert(reaction).second; reactor_assert(result); } @@ -62,8 +61,8 @@ void Timer::cleanup() noexcept { BaseAction::cleanup(); // schedule the timer again if (period_ != Duration::zero()) { - Tag now = Tag::from_logical_time(environment()->logical_time()); - Tag next = now.delay(period_); + const Tag now = Tag::from_logical_time(environment()->logical_time()); + const Tag next = now.delay(period_); environment()->scheduler()->schedule_sync(this, next); } } @@ -74,7 +73,7 @@ ShutdownTrigger::ShutdownTrigger(const std::string& name, Reactor* container) void ShutdownTrigger::setup() noexcept { BaseAction::setup(); } void ShutdownTrigger::shutdown() { - Tag tag = Tag::from_logical_time(environment()->logical_time()).delay(); + const Tag tag = Tag::from_logical_time(environment()->logical_time()).delay(); environment()->scheduler()->schedule_sync(this, tag); } diff --git a/lib/environment.cc b/lib/environment.cc index 5a659e60..a25cedf9 100644 --- a/lib/environment.cc +++ b/lib/environment.cc @@ -41,7 +41,7 @@ Environment::Environment(const std::string& name, Environment* containing_enviro , top_environment_(containing_environment_->top_environment_) , scheduler_(this) , timeout_(containing_environment->timeout()) { - [[maybe_unused]] bool result = containing_environment->contained_environments_.insert(this).second; + [[maybe_unused]] const bool result = containing_environment->contained_environments_.insert(this).second; reactor_assert(result); } @@ -50,7 +50,7 @@ void Environment::register_reactor(Reactor* reactor) { validate(this->phase() == Phase::Construction || this->phase() == Phase::Mutation, "Reactors may only be registered during construction phase!"); validate(reactor->is_top_level(), "The environment may only contain top level reactors!"); - [[maybe_unused]] bool result = top_level_reactors_.insert(reactor).second; + [[maybe_unused]] const bool result = top_level_reactors_.insert(reactor).second; reactor_assert(result); } @@ -66,7 +66,7 @@ void Environment::register_input_action(BaseAction* action) { reactor_assert(action != nullptr); validate(this->phase() == Phase::Construction || this->phase() == Phase::Assembly, "Input actions may only be registered during construction or assembly phase!"); - [[maybe_unused]] bool result = input_actions_.insert(action).second; + [[maybe_unused]] const bool result = input_actions_.insert(action).second; reactor_assert(result); run_forever_ = true; } @@ -169,7 +169,7 @@ void Environment::build_dependency_graph(Reactor* reactor) { // connect all reactions_ this reaction depends on for (auto* reaction : reactor->reactions()) { for (auto* dependency : reaction->dependencies()) { - auto* source = dependency; + const auto* source = dependency; while (source->has_inward_binding()) { source = source->inward_binding(); } diff --git a/lib/multiport.cc b/lib/multiport.cc index 22f6477e..43486e07 100644 --- a/lib/multiport.cc +++ b/lib/multiport.cc @@ -20,8 +20,8 @@ auto reactor::BaseMultiport::get_set_callback(std::size_t index) noexcept -> rea }; } -void reactor::BaseMultiport::set_present(std::size_t index) { - auto calculated_index = size_.fetch_add(1, std::memory_order_relaxed); +void reactor::BaseMultiport::set_present(const std::size_t index) { + const auto calculated_index = size_.fetch_add(1, std::memory_order_relaxed); reactor_assert(calculated_index < present_ports_.size()); diff --git a/lib/port.cc b/lib/port.cc index e11a5315..5b9adec5 100644 --- a/lib/port.cc +++ b/lib/port.cc @@ -54,7 +54,7 @@ void BasePort::register_antidependency(Reaction* reaction) noexcept { "Antidependent input ports must belong to a contained reactor"); } - [[maybe_unused]] bool result = anti_dependencies_.insert(reaction).second; + [[maybe_unused]] const bool result = anti_dependencies_.insert(reaction).second; reactor_assert(result); } @@ -92,7 +92,7 @@ void Port::instantiate_connection_to(const ConnectionProperties& propertie reactor_assert(properties.type_ != ConnectionType::Normal); Environment* enclave = downstream[0]->environment(); - auto index = this->container()->number_of_connections(); + const auto index = this->container()->number_of_connections(); if (properties.type_ == ConnectionType::Delayed) { connection = std::make_unique>( diff --git a/lib/reaction.cc b/lib/reaction.cc index 03802cf5..db79f0ba 100644 --- a/lib/reaction.cc +++ b/lib/reaction.cc @@ -31,7 +31,7 @@ void Reaction::declare_trigger(BaseAction* action) { validate(this->container() == action->container(), "Action triggers must belong to the same reactor as the triggered " "reaction"); - [[maybe_unused]] bool result = action_triggers_.insert(action).second; + [[maybe_unused]] const bool result = action_triggers_.insert(action).second; reactor_assert(result); action->register_trigger(this); } @@ -43,7 +43,7 @@ void Reaction::declare_schedulable_action(BaseAction* action) { validate(this->container() == action->container(), "Scheduable actions must belong to the same reactor as the " "triggered reaction"); - [[maybe_unused]] bool result = scheduable_actions_.insert(action).second; + [[maybe_unused]] const bool result = scheduable_actions_.insert(action).second; reactor_assert(result); action->register_scheduler(this); } @@ -83,7 +83,7 @@ void Reaction::declare_dependency(BasePort* port) { "Dependent output ports must belong to a contained reactor"); } - [[maybe_unused]] bool result = dependencies_.insert(port).second; + [[maybe_unused]] const bool result = dependencies_.insert(port).second; reactor_assert(result); port->register_dependency(this, false); } @@ -101,16 +101,15 @@ void Reaction::declare_antidependency(BasePort* port) { "Antidependent input ports must belong to a contained reactor"); } - [[maybe_unused]] bool result = antidependencies_.insert(port).second; + [[maybe_unused]] const bool result = antidependencies_.insert(port).second; reactor_assert(result); port->register_antidependency(this); } -void Reaction::trigger() { +void Reaction::trigger() const { if (has_deadline()) { reactor_assert(deadline_handler_ != nullptr); - auto lag = Reactor::get_physical_time() - container()->get_logical_time(); - if (lag > deadline_) { + if (const auto lag = Reactor::get_physical_time() - container()->get_logical_time(); lag > deadline_) { deadline_handler_(); return; } diff --git a/lib/reactor.cc b/lib/reactor.cc index 784ba48d..459f10bc 100644 --- a/lib/reactor.cc +++ b/lib/reactor.cc @@ -31,7 +31,7 @@ void Reactor::register_action([[maybe_unused]] BaseAction* action) { reactor::validate(this->environment()->phase() == Phase::Construction || this->environment()->phase() == Phase::Assembly, "Actions can only be registered during construction phase!"); - [[maybe_unused]] bool result = actions_.insert(action).second; + [[maybe_unused]] const bool result = actions_.insert(action).second; reactor_assert(result); Statistics::increment_actions(); } @@ -50,7 +50,7 @@ void Reactor::register_input(BasePort* port) { reactor::validate(this->environment()->phase() == Phase::Construction || this->environment()->phase() == Phase::Mutation, "Ports can only be registered during construction phase!"); - [[maybe_unused]] bool result = inputs_.insert(port).second; + [[maybe_unused]] const bool result = inputs_.insert(port).second; reactor_assert(result); Statistics::increment_ports(); } @@ -60,7 +60,7 @@ void Reactor::unregister_input(BasePort* port) { reactor::validate(this->environment()->phase() == Phase::Construction || this->environment()->phase() == Phase::Mutation, "Ports can only be registered during construction phase!"); - std::size_t number_of_elements = inputs_.erase(port); + const std::size_t number_of_elements = inputs_.erase(port); reactor_assert(number_of_elements > 0); Statistics::decrement_ports(); } @@ -70,7 +70,7 @@ void Reactor::register_output(BasePort* port) { reactor::validate(this->environment()->phase() == Phase::Construction || this->environment()->phase() == Phase::Mutation, "Ports can only be registered during construction phase!"); - [[maybe_unused]] bool result = outputs_.insert(port).second; + [[maybe_unused]] const bool result = outputs_.insert(port).second; reactor_assert(result); Statistics::increment_ports(); } @@ -81,7 +81,6 @@ void Reactor::unregister_output(BasePort* port) { this->environment()->phase() == Phase::Mutation, "Ports can only be registered during construction phase!"); outputs_.erase(port); - // reactor_assert(number_of_elements > 0); Statistics::decrement_ports(); } @@ -90,7 +89,7 @@ void Reactor::register_reaction([[maybe_unused]] Reaction* reaction) { validate(this->environment()->phase() == Phase::Construction || this->environment()->phase() == Phase::Mutation, "Reactions can only be registered during construction phase!"); - [[maybe_unused]] bool result = reactions_.insert(reaction).second; + [[maybe_unused]] const bool result = reactions_.insert(reaction).second; reactor_assert(result); Statistics::increment_reactions(); } @@ -108,7 +107,7 @@ void Reactor::register_reactor([[maybe_unused]] Reactor* reactor) { reactor_assert(reactor != nullptr); validate(this->environment()->phase() == Phase::Construction || this->environment()->phase() == Phase::Mutation, "Reactions can only be registered during construction phase!"); - [[maybe_unused]] bool result = reactors_.insert(reactor).second; + [[maybe_unused]] const bool result = reactors_.insert(reactor).second; reactor_assert(result); Statistics::increment_reactor_instances(); } @@ -123,7 +122,7 @@ void Reactor::unregister_reactor([[maybe_unused]] Reactor* reactor) { void Reactor::register_connection([[maybe_unused]] std::unique_ptr&& connection) { reactor_assert(connection != nullptr); - [[maybe_unused]] auto result = connections_.insert(std::move(connection)).second; + [[maybe_unused]] const auto result = connections_.insert(std::move(connection)).second; reactor_assert(result); } diff --git a/lib/scheduler.cc b/lib/scheduler.cc index 5c3532ad..63ab759e 100644 --- a/lib/scheduler.cc +++ b/lib/scheduler.cc @@ -104,7 +104,7 @@ auto ReadyQueue::pop() -> Reaction* { // FIXME: Protect against underflow? } - auto pos = old_size - 1; + const auto pos = old_size - 1; return queue_[pos]; } @@ -115,8 +115,8 @@ void ReadyQueue::fill_up(std::vector& ready_reactions) { // update the atomic size counter and release the semaphore to wake up // waiting worker threads - auto new_size = static_cast(queue_.size()); - auto old_size = size_.exchange(new_size, std::memory_order_acq_rel); + const auto new_size = static_cast(queue_.size()); + const auto old_size = size_.exchange(new_size, std::memory_order_acq_rel); // calculate how many workers to wake up. -old_size indicates the number of // workers who started waiting since the last update. @@ -128,11 +128,10 @@ void ReadyQueue::fill_up(std::vector& ready_reactions) { // one worker running running, new_size - running_workers indicates the // number of additional workers needed to process all reactions. waiting_workers_ += -old_size; - std::ptrdiff_t running_workers{num_workers_ - waiting_workers_}; - auto workers_to_wakeup = std::min(waiting_workers_, new_size - running_workers); + const std::ptrdiff_t running_workers{num_workers_ - waiting_workers_}; // wakeup other workers_ - if (workers_to_wakeup > 0) { + if (auto workers_to_wakeup = std::min(waiting_workers_, new_size - running_workers); workers_to_wakeup > 0) { waiting_workers_ -= workers_to_wakeup; log_.debug() << "Wakeup " << workers_to_wakeup << " workers"; sem_.release(static_cast(workers_to_wakeup)); @@ -158,8 +157,7 @@ auto EventQueue::extract_next_event() -> ActionListPtr { auto EventQueue::insert_event_at(const Tag& tag) -> const ActionListPtr& { auto shared_lock = std::shared_lock(mutex_); - auto event_it = event_queue_.find(tag); - if (event_it == event_queue_.end()) { + if (const auto event_it = event_queue_.find(tag); event_it == event_queue_.end()) { shared_lock.unlock(); { auto unique_lock = std::unique_lock(mutex_); @@ -344,8 +342,8 @@ void Scheduler::next() { // NOLINT(readability-function-cognitive-complexity) if (stop_) { continue_execution_ = false; log_.debug() << "Shutting down the scheduler"; - Tag t_next = Tag::from_logical_time(logical_time_).delay(); - if (!event_queue_.empty() && t_next == event_queue_.next_tag()) { + if (Tag t_next = Tag::from_logical_time(logical_time_).delay(); + !event_queue_.empty() && t_next == event_queue_.next_tag()) { log_.debug() << "Trigger the last round of reactions including all " "shutdown reactions"; triggered_actions_ = event_queue_.extract_next_event(); @@ -359,7 +357,7 @@ void Scheduler::next() { // NOLINT(readability-function-cognitive-complexity) // synchronize with physical time if not in fast forward mode if (!environment_->fast_fwd_execution()) { log_.debug() << "acquire tag " << t_next << " from physical time barrier"; - bool result = PhysicalTimeBarrier::acquire_tag( + const bool result = PhysicalTimeBarrier::acquire_tag( t_next, lock, this, [&t_next, this]() { return t_next != event_queue_.next_tag(); }); // If acquire tag returns false, then a new event was inserted into the queue and we need to start over if (!result) { @@ -372,7 +370,7 @@ void Scheduler::next() { // NOLINT(readability-function-cognitive-complexity) bool result{true}; for (auto* action : environment_->input_actions_) { log_.debug() << "acquire tag " << t_next << " from input action " << action->fqn(); - bool inner_result = + const bool inner_result = action->acquire_tag(t_next, lock, [&t_next, this]() { return t_next != event_queue_.next_tag(); }); // If the wait was aborted or if the next tag changed in the meantime, // we need to break from the loop and continue with the main loop. diff --git a/lib/time.cc b/lib/time.cc index 34f58b35..75bea23e 100644 --- a/lib/time.cc +++ b/lib/time.cc @@ -27,10 +27,10 @@ inline namespace operators { auto operator<<(std::ostream& os, TimePoint tp) -> std::ostream& { std::array buf{}; - time_t time = + const time_t time = std::chrono::system_clock::to_time_t(std::chrono::time_point_cast(tp)); - auto res = std::strftime(buf.data(), sizeof(buf), "%Y-%m-%d %H:%M:%S", std::localtime(&time)); - auto epoch = std::chrono::duration_cast(tp.time_since_epoch()); + const auto res = std::strftime(buf.data(), sizeof(buf), "%Y-%m-%d %H:%M:%S", std::localtime(&time)); + const auto epoch = std::chrono::duration_cast(tp.time_since_epoch()); if (res != 0) { os << buf.data() << '.' << std::setw(NANOSECOND_DIGITS) << std::setfill('0')