diff --git a/.clang-tidy b/.clang-tidy index 421e13eb..ec3cc51e 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -11,7 +11,8 @@ Checks: ' llvm-*, cert-*, -clang-analyzer-core.CallAndMessage, - -readability-redundant-member-init' + -readability-redundant-member-init, + -boost-use-ranges' WarningsAsErrors: true HeaderFilterRegex: '' FormatStyle: none diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 026e549d..031be64f 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -1 +1 @@ -* @cmnrd @tanneberger +* @cmnrd @tanneberger @edwardalee diff --git a/examples/count/main.cc b/examples/count/main.cc index e0c6e92b..e62a9331 100644 --- a/examples/count/main.cc +++ b/examples/count/main.cc @@ -12,8 +12,8 @@ class Count : public Reactor { LogicalAction counter{"counter", this}; // reactions_ - Reaction r_init{"r_init", 1, this, [this]() { init(); }}; - Reaction r_counter{"r_counter", 2, this, [this]() { print_count(); }}; + Reaction r_init{"r_init", 1, this, [this]() -> void { init(); }}; + Reaction r_counter{"r_counter", 2, this, [this]() -> void { print_count(); }}; public: explicit Count(Environment* env) diff --git a/examples/hello/main.cc b/examples/hello/main.cc index 3b02fd89..00a7ce87 100644 --- a/examples/hello/main.cc +++ b/examples/hello/main.cc @@ -13,8 +13,8 @@ class Hello : public Reactor { ShutdownTrigger sa{"terminate", this}; // reactions - Reaction r_hello{"r_hello", 1, this, [this]() { hello(); }}; - Reaction r_terminate{"r_terminate", 2, this, [this]() { terminate(); }}; + Reaction r_hello{"r_hello", 1, this, [this]() -> void { hello(); }}; + Reaction r_terminate{"r_terminate", 2, this, [this]() -> void { terminate(); }}; public: explicit Hello(Environment* env) diff --git a/examples/ports/main.cc b/examples/ports/main.cc index 671d89b7..7a719af2 100644 --- a/examples/ports/main.cc +++ b/examples/ports/main.cc @@ -8,7 +8,7 @@ using namespace std::chrono_literals; class Trigger : public Reactor { private: Timer timer; - Reaction r_timer{"r_timer", 1, this, [this]() { on_timer(); }}; + Reaction r_timer{"r_timer", 1, this, [this]() -> void { on_timer(); }}; public: Trigger(const std::string& name, Environment* env, Duration period) @@ -28,7 +28,7 @@ class Trigger : public Reactor { class Counter : public Reactor { private: int value_{0}; - Reaction r_trigger{"r_trigger", 1, this, [this]() { on_trigger(); }}; + Reaction r_trigger{"r_trigger", 1, this, [this]() -> void { on_trigger(); }}; public: Counter(const std::string& name, Environment* env) @@ -51,7 +51,7 @@ class Counter : public Reactor { class Printer : public Reactor { private: - Reaction r_value{"r_value", 1, this, [this]() { on_value(); }}; + Reaction r_value{"r_value", 1, this, [this]() -> void { on_value(); }}; public: Input value{"value", this}; // NOLINT @@ -69,7 +69,7 @@ class Printer : public Reactor { class Adder : public Reactor { private: - Reaction r_add{"r_add", 1, this, [this]() { add(); }}; + Reaction r_add{"r_add", 1, this, [this]() -> void { add(); }}; public: Input i1{"i1", this}; // NOLINT diff --git a/examples/power_train/main.cc b/examples/power_train/main.cc index 05efe57f..ca872671 100644 --- a/examples/power_train/main.cc +++ b/examples/power_train/main.cc @@ -15,7 +15,7 @@ class LeftPedal : public Reactor { PhysicalAction req{"req", this}; // reactions - Reaction r1{"1", 1, this, [this]() { reaction_1(); }}; + Reaction r1{"1", 1, this, [this]() -> void { reaction_1(); }}; void reaction_1() {} @@ -41,8 +41,8 @@ class RightPedal : public Reactor { PhysicalAction pol{"pol", this}; // reactions - Reaction r1{"1", 1, this, [this]() { reaction_1(); }}; - Reaction r2{"2", 2, this, [this]() { reaction_2(); }}; + Reaction r1{"1", 1, this, [this]() -> void { reaction_1(); }}; + Reaction r2{"2", 2, this, [this]() -> void { reaction_2(); }}; void reaction_1() {} void reaction_2() {} @@ -67,7 +67,7 @@ class BrakeControl : public Reactor { Output force{"force", this}; // NOLINT private: - Reaction r1{"1", 1, this, [this]() { reaction_1(); }}; + Reaction r1{"1", 1, this, [this]() -> void { reaction_1(); }}; void reaction_1() {} @@ -94,9 +94,9 @@ class EngineControl : public Reactor { PhysicalAction rev{"rev", this}; // reactions - Reaction r1{"1", 1, this, [this]() { reaction_1(); }}; - Reaction r2{"2", 2, this, [this]() { reaction_2(); }}; - Reaction r3{"3", 3, this, [this]() { reaction_3(); }}; + Reaction r1{"1", 1, this, [this]() -> void { reaction_1(); }}; + Reaction r2{"2", 2, this, [this]() -> void { reaction_2(); }}; + Reaction r3{"3", 3, this, [this]() -> void { reaction_3(); }}; void reaction_1() {} void reaction_2() {} @@ -125,7 +125,7 @@ class Brake : public Reactor { private: // reactions_ - Reaction r1{"1", 1, this, [this]() { reaction_1(); }}; + Reaction r1{"1", 1, this, [this]() -> void { reaction_1(); }}; void reaction_1() {} @@ -143,7 +143,7 @@ class Engine : public Reactor { private: // reactions_ - Reaction r1{"1", 1, this, [this]() { reaction_1(); }}; + Reaction r1{"1", 1, this, [this]() -> void { reaction_1(); }}; void reaction_1() {} diff --git a/include/reactor-cpp/connection.hh b/include/reactor-cpp/connection.hh index 106738fc..6b217c59 100644 --- a/include/reactor-cpp/connection.hh +++ b/include/reactor-cpp/connection.hh @@ -66,7 +66,7 @@ protected: : Connection(name, environment, is_logical, delay) {} auto upstream_set_callback() noexcept -> PortCallback override { - return [this](const BasePort& port) { + return [this](const BasePort& port) -> void { // 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) { @@ -124,7 +124,7 @@ public: , log_{this->fqn()} {}; auto upstream_set_callback() noexcept -> PortCallback override { - return [this](const BasePort& port) { + return [this](const BasePort& port) -> void { // We know that port must be of type Port // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast) auto& typed_port = reinterpret_cast&>(port); @@ -177,7 +177,7 @@ public: void bind_upstream_port(Port* port) override { Connection::bind_upstream_port(port); - port->environment()->scheduler()->register_release_tag_callback([this](const LogicalTime& tag) { + port->environment()->scheduler()->register_release_tag_callback([this](const LogicalTime& tag) -> void { logical_time_barrier_.release_tag(tag); log_.debug() << "upstream released tag " << tag; this->environment()->scheduler()->notify(); @@ -191,7 +191,7 @@ public: : EnclaveConnection(name, enclave, delay) {} auto upstream_set_callback() noexcept -> PortCallback override { - return [&](const BasePort& port) { + return [&](const BasePort& port) -> void { // This callback will be called from a reaction executing in the context // of the upstream port. Hence, we can retrieve the current tag directly // without locking. @@ -228,7 +228,7 @@ public: : EnclaveConnection(name, enclave) {} auto upstream_set_callback() noexcept -> PortCallback override { - return [this](const BasePort& port) { + return [this](const BasePort& port) -> void { // We know that port must be of type Port // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast) auto& typed_port = reinterpret_cast&>(port); diff --git a/include/reactor-cpp/connection_properties.hh b/include/reactor-cpp/connection_properties.hh index e9e1b452..0b18d23e 100644 --- a/include/reactor-cpp/connection_properties.hh +++ b/include/reactor-cpp/connection_properties.hh @@ -15,7 +15,7 @@ namespace reactor { -enum ConnectionType : std::uint8_t { +enum class ConnectionType : std::uint8_t { Normal, Delayed, Enclaved, diff --git a/include/reactor-cpp/graph.hh b/include/reactor-cpp/graph.hh index 4009e169..81225bbd 100644 --- a/include/reactor-cpp/graph.hh +++ b/include/reactor-cpp/graph.hh @@ -32,21 +32,12 @@ private: public: Graph() noexcept = default; - Graph(const Graph& graph) noexcept - : graph_(graph.graph_) {} - Graph(const Graph&& graph) noexcept - : graph_(std::move(graph.graph_)) {} + Graph(const Graph&) noexcept = default; + Graph(Graph&&) noexcept = default; ~Graph() noexcept = default; - auto operator=(const Graph other) noexcept -> Graph& { - graph_ = other.graph_; - return *this; - } - - auto operator=(Graph&& other) noexcept -> Graph& { - graph_ = std::move(other.graph_); - return *this; - } + auto operator=(const Graph&) noexcept -> Graph& = default; + auto operator=(Graph&&) noexcept -> Graph& = default; // adds a single edge to the graph structure void add_edge(E source, E destination, P properties) noexcept { diff --git a/include/reactor-cpp/impl/action_impl.hh b/include/reactor-cpp/impl/action_impl.hh index a7ce1d92..bc70ca96 100644 --- a/include/reactor-cpp/impl/action_impl.hh +++ b/include/reactor-cpp/impl/action_impl.hh @@ -31,7 +31,7 @@ template template void Action::schedule(const Immutable scheduler->schedule_sync(this, tag); events_[tag] = value_ptr; } else { - std::lock_guard lock{mutex_events_}; + std::scoped_lock lock{mutex_events_}; // We must call schedule_async while holding the mutex, because otherwise // the scheduler could already start processing the event that we schedule // and call setup() on this action before we insert the value in events_. @@ -68,7 +68,7 @@ template auto Action::schedule_at(const ImmutableValuePtr& value scheduler->schedule_sync(this, tag); events_[tag] = value_ptr; } else { - std::lock_guard lock{mutex_events_}; + std::scoped_lock lock{mutex_events_}; // We must call schedule_async while holding the mutex, because otherwise // the scheduler could already start processing the event that we schedule // and call setup() on this action before we insert the value in events_. diff --git a/include/reactor-cpp/multiport.hh b/include/reactor-cpp/multiport.hh index 3e66cee5..16f53280 100644 --- a/include/reactor-cpp/multiport.hh +++ b/include/reactor-cpp/multiport.hh @@ -33,7 +33,7 @@ private: void reset() noexcept { size_.store(0, std::memory_order_relaxed); } [[nodiscard]] auto get_set_callback(std::size_t index) noexcept -> PortCallback; - const PortCallback clean_callback_{[this]([[maybe_unused]] const BasePort& port) { this->reset(); }}; + const PortCallback clean_callback_{[this]([[maybe_unused]] const BasePort& port) -> void { this->reset(); }}; [[nodiscard]] auto get_clean_callback() const noexcept -> const PortCallback& { return clean_callback_; } diff --git a/include/reactor-cpp/semaphore.hh b/include/reactor-cpp/semaphore.hh index bc198547..5654799b 100644 --- a/include/reactor-cpp/semaphore.hh +++ b/include/reactor-cpp/semaphore.hh @@ -27,7 +27,7 @@ public: void release(int increment) { { - std::lock_guard lock_guard(mutex_); + std::scoped_lock lock_guard(mutex_); count_ += increment; } cv_.notify_all(); @@ -35,7 +35,7 @@ public: void acquire() { std::unique_lock lock_guard(mutex_); - cv_.wait(lock_guard, [&]() { return count_ != 0; }); + cv_.wait(lock_guard, [&]() -> bool { return count_ != 0; }); count_--; } }; diff --git a/include/reactor-cpp/time_barrier.hh b/include/reactor-cpp/time_barrier.hh index a5874106..8e1992f2 100644 --- a/include/reactor-cpp/time_barrier.hh +++ b/include/reactor-cpp/time_barrier.hh @@ -85,7 +85,7 @@ public: if (try_acquire_tag(tag)) { return true; } - scheduler_->wait(lock, [this, &tag, &abort_waiting]() { return try_acquire_tag(tag) || abort_waiting(); }); + scheduler_->wait(lock, [this, &tag, &abort_waiting]() -> bool { return try_acquire_tag(tag) || abort_waiting(); }); return !abort_waiting(); } }; diff --git a/lib/environment.cc b/lib/environment.cc index 52c0b6bf..e9944f2c 100644 --- a/lib/environment.cc +++ b/lib/environment.cc @@ -184,7 +184,7 @@ void Environment::build_dependency_graph(Reactor* reactor) { void Environment::sync_shutdown() { { - std::lock_guard lock{shutdown_mutex_}; + std::scoped_lock lock{shutdown_mutex_}; if (phase_ >= Phase::Shutdown) { // sync_shutdown() was already called -> abort @@ -347,7 +347,7 @@ auto Environment::startup(const TimePoint& start_time) -> std::thread { // start processing events phase_ = Phase::Execution; - return std::thread([this, start_time]() { + return std::thread([this, start_time]() -> void { std::vector threads; threads.reserve(contained_environments_.size()); // startup all contained environments recursively diff --git a/lib/multiport.cc b/lib/multiport.cc index c6674cb1..92ffc20d 100644 --- a/lib/multiport.cc +++ b/lib/multiport.cc @@ -12,7 +12,7 @@ auto reactor::BaseMultiport::get_set_callback(std::size_t index) noexcept -> reactor::PortCallback { // tells the parent multiport that this port has been set. - return [this, index](const BasePort& port) { + return [this, index](const BasePort& port) -> void { // if the port is present, the callback was already invoked before if (!port.is_present()) { this->set_present(index); diff --git a/lib/port.cc b/lib/port.cc index 7260c661..4a1b749c 100644 --- a/lib/port.cc +++ b/lib/port.cc @@ -129,7 +129,7 @@ void Port::instantiate_connection_to(const ConnectionProperties& propertie // same port (one if the port is in a multiport, and one if it is upstream of // a delayed connection). auto compose_callbacks(const PortCallback& callback1, const PortCallback& callback2) -> PortCallback { - return [=](const BasePort& port) { + return [=](const BasePort& port) -> void { callback1(port); callback2(port); }; diff --git a/lib/scheduler.cc b/lib/scheduler.cc index 5c3532ad..336d87b8 100644 --- a/lib/scheduler.cc +++ b/lib/scheduler.cc @@ -246,7 +246,7 @@ void Scheduler::start() { // Other schedulers (enclaves or federates) could try to access our logical // time and our event queue. Thus, we need to lock the main scheduling mutex // in order to avoid data races. - std::lock_guard lock_guard(scheduling_mutex_); + std::scoped_lock lock_guard(scheduling_mutex_); // Initialize our logical time to the value right before the start tag. This // is important for usage with enclaves/federates, to indicate, that no events @@ -334,7 +334,7 @@ void Scheduler::next() { // NOLINT(readability-function-cognitive-complexity) if (event_queue_.empty() && !stop_) { if (environment_->run_forever()) { // wait for a new asynchronous event - cv_schedule_.wait(lock, [this]() { return !event_queue_.empty() || stop_; }); + cv_schedule_.wait(lock, [this]() -> bool { return !event_queue_.empty() || stop_; }); } else { log_.debug() << "No more events in queue_. -> Terminate!"; environment_->sync_shutdown(); @@ -360,7 +360,7 @@ void Scheduler::next() { // NOLINT(readability-function-cognitive-complexity) if (!environment_->fast_fwd_execution()) { log_.debug() << "acquire tag " << t_next << " from physical time barrier"; bool result = PhysicalTimeBarrier::acquire_tag( - t_next, lock, this, [&t_next, this]() { return t_next != event_queue_.next_tag(); }); + t_next, lock, this, [&t_next, this]() -> bool { 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) { log_.debug() << "abort waiting and restart as the event queue was modified"; @@ -372,8 +372,8 @@ 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 = - action->acquire_tag(t_next, lock, [&t_next, this]() { return t_next != event_queue_.next_tag(); }); + bool inner_result = action->acquire_tag( + t_next, lock, [&t_next, this]() -> bool { 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. if (!inner_result || t_next != event_queue_.next_tag()) { @@ -461,7 +461,7 @@ void Scheduler::schedule_sync(BaseAction* action, const Tag& tag) { auto Scheduler::schedule_async(BaseAction* action, const Duration& delay) -> Tag { Tag tag; { - std::lock_guard lock_guard(scheduling_mutex_); + std::scoped_lock lock_guard(scheduling_mutex_); tag = Tag::from_physical_time(get_physical_time() + delay); schedule_sync(action, tag); } @@ -471,7 +471,7 @@ auto Scheduler::schedule_async(BaseAction* action, const Duration& delay) -> Tag auto Scheduler::schedule_async_at(BaseAction* action, const Tag& tag) -> bool { { - std::lock_guard lock_guard(scheduling_mutex_); + std::scoped_lock lock_guard(scheduling_mutex_); if (tag <= logical_time_) { return false; } @@ -483,7 +483,7 @@ auto Scheduler::schedule_async_at(BaseAction* action, const Tag& tag) -> bool { auto Scheduler::schedule_empty_async_at(const Tag& tag) -> bool { { - std::lock_guard lock_guard(scheduling_mutex_); + std::scoped_lock lock_guard(scheduling_mutex_); if (tag <= logical_time_) { // If we try to insert an empty event at the current logical time, then we // succeeded because there must be an event at this tag that is currently