Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -1 +1 @@
* @cmnrd @tanneberger
* @cmnrd @tanneberger @edwardalee
4 changes: 2 additions & 2 deletions examples/count/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ class Count : public Reactor {
LogicalAction<int> 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)
Expand Down
4 changes: 2 additions & 2 deletions examples/hello/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions examples/ports/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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<int> value{"value", this}; // NOLINT
Expand All @@ -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<int> i1{"i1", this}; // NOLINT
Expand Down
18 changes: 9 additions & 9 deletions examples/power_train/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class LeftPedal : public Reactor {
PhysicalAction<void> req{"req", this};

// reactions
Reaction r1{"1", 1, this, [this]() { reaction_1(); }};
Reaction r1{"1", 1, this, [this]() -> void { reaction_1(); }};

void reaction_1() {}

Expand All @@ -41,8 +41,8 @@ class RightPedal : public Reactor {
PhysicalAction<void> 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() {}
Expand All @@ -67,7 +67,7 @@ class BrakeControl : public Reactor {
Output<void> 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() {}

Expand All @@ -94,9 +94,9 @@ class EngineControl : public Reactor {
PhysicalAction<void> 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() {}
Expand Down Expand Up @@ -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() {}

Expand All @@ -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() {}

Expand Down
10 changes: 5 additions & 5 deletions include/reactor-cpp/connection.hh
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ protected:
: Connection<T>(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<T>
auto& typed_port = reinterpret_cast<const Port<T>&>(port); // NOLINT(cppcoreguidelines-pro-type-reinterpret-cast)
if constexpr (std::is_same<T, void>::value) {
Expand Down Expand Up @@ -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<T>
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
auto& typed_port = reinterpret_cast<const Port<T>&>(port);
Expand Down Expand Up @@ -177,7 +177,7 @@ public:

void bind_upstream_port(Port<T>* port) override {
Connection<T>::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();
Expand All @@ -191,7 +191,7 @@ public:
: EnclaveConnection<T>(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.
Expand Down Expand Up @@ -228,7 +228,7 @@ public:
: EnclaveConnection<T>(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<T>
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
auto& typed_port = reinterpret_cast<const Port<T>&>(port);
Expand Down
2 changes: 1 addition & 1 deletion include/reactor-cpp/connection_properties.hh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

namespace reactor {

enum ConnectionType : std::uint8_t {
enum class ConnectionType : std::uint8_t {
Normal,
Delayed,
Enclaved,
Expand Down
17 changes: 4 additions & 13 deletions include/reactor-cpp/graph.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions include/reactor-cpp/impl/action_impl.hh
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ template <class T> template <class Dur> void Action<T>::schedule(const Immutable
scheduler->schedule_sync(this, tag);
events_[tag] = value_ptr;
} else {
std::lock_guard<std::mutex> 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_.
Expand Down Expand Up @@ -68,7 +68,7 @@ template <class T> auto Action<T>::schedule_at(const ImmutableValuePtr<T>& value
scheduler->schedule_sync(this, tag);
events_[tag] = value_ptr;
} else {
std::lock_guard<std::mutex> 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_.
Expand Down
2 changes: 1 addition & 1 deletion include/reactor-cpp/multiport.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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_; }

Expand Down
4 changes: 2 additions & 2 deletions include/reactor-cpp/semaphore.hh
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ public:

void release(int increment) {
{
std::lock_guard<std::mutex> lock_guard(mutex_);
std::scoped_lock lock_guard(mutex_);
count_ += increment;
}
cv_.notify_all();
}

void acquire() {
std::unique_lock<std::mutex> lock_guard(mutex_);
cv_.wait(lock_guard, [&]() { return count_ != 0; });
cv_.wait(lock_guard, [&]() -> bool { return count_ != 0; });
count_--;
}
};
Expand Down
2 changes: 1 addition & 1 deletion include/reactor-cpp/time_barrier.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
};
Expand Down
4 changes: 2 additions & 2 deletions lib/environment.cc
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ void Environment::build_dependency_graph(Reactor* reactor) {

void Environment::sync_shutdown() {
{
std::lock_guard<std::mutex> lock{shutdown_mutex_};
std::scoped_lock lock{shutdown_mutex_};

if (phase_ >= Phase::Shutdown) {
// sync_shutdown() was already called -> abort
Expand Down Expand Up @@ -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<std::thread> threads;
threads.reserve(contained_environments_.size());
// startup all contained environments recursively
Expand Down
2 changes: 1 addition & 1 deletion lib/multiport.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion lib/port.cc
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ void Port<void>::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);
};
Expand Down
16 changes: 8 additions & 8 deletions lib/scheduler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::mutex> 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
Expand Down Expand Up @@ -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();
Expand All @@ -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";
Expand All @@ -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()) {
Expand Down Expand Up @@ -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<std::mutex> lock_guard(scheduling_mutex_);
std::scoped_lock lock_guard(scheduling_mutex_);
tag = Tag::from_physical_time(get_physical_time() + delay);
schedule_sync(action, tag);
}
Expand All @@ -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<std::mutex> lock_guard(scheduling_mutex_);
std::scoped_lock lock_guard(scheduling_mutex_);
if (tag <= logical_time_) {
return false;
}
Expand All @@ -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<std::mutex> 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
Expand Down
Loading