Skip to content

Commit

Permalink
clang-format
Browse files Browse the repository at this point in the history
  • Loading branch information
tanneberger committed Dec 13, 2024
1 parent 95c55bf commit 9e1b6ed
Show file tree
Hide file tree
Showing 27 changed files with 238 additions and 192 deletions.
52 changes: 52 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
.PHONY: clean test coverage asan format format-check ci lf-test lib proto

test: unit-test lf-test

# Generate protobuf code
proto:
python3 external/nanopb/generator/nanopb_generator.py -Iexternal/nanopb/generator/proto/ -Iexternal/proto -L'#include "nanopb/%s"' -Dexternal/proto message.proto

# Build reactor-uc as a static library
lib:
cmake -Bbuild
cmake --build build
make -C build

# Build and run the unit tests
unit-test:
cmake -Bbuild -DBUILD_TESTS=ON
cmake --build build
make test -C build

# Build and run lf tests
lf-test:
make -C test/lf

# Get coverage data on unit tests
coverage:
cmake -Bbuild -DBUILD_TESTS=ON -DTEST_COVERAGE=ON
cmake --build build
make coverage -C build

# Compile tests with AddressSanitizer and run them
asan:
cmake -Bbuild -DASAN=ON -DBUILD_TESTS=ON
cmake --build build
make test -C build

# Format the code base
SRC_FILES := $(shell find ./lib -name '*.cc' -print)
HDR_FILES := $(shell find ./include -name '*.hh' -print)

format:
clang-format -i -style=file $(SRC_FILES) $(HDR_FILES)

# Check that the code base is formatted
format-check:
clang-format --dry-run --Werror -style=file $(SRC_FILES) $(HDR_FILES)

# Run the entire CI flow
ci: clean test coverage format-check

clean:
rm -rf build
12 changes: 6 additions & 6 deletions include/reactor-cpp/connection.hh
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ public:
};
}

auto acquire_tag(const Tag& tag, std::unique_lock<std::mutex>& lock,
const std::function<bool(void)>& abort_waiting) -> bool override {
auto acquire_tag(const Tag& tag, std::unique_lock<std::mutex>& lock, const std::function<bool(void)>& abort_waiting)
-> bool override {
reactor_assert(lock.owns_lock());
log_.debug() << "downstream tries to acquire tag " << tag;

Expand Down Expand Up @@ -210,8 +210,8 @@ public:
};
}

auto acquire_tag(const Tag& tag, std::unique_lock<std::mutex>& lock,
const std::function<bool(void)>& abort_waiting) -> bool override {
auto acquire_tag(const Tag& tag, std::unique_lock<std::mutex>& lock, const std::function<bool(void)>& abort_waiting)
-> bool override {
// Since this is a delayed connection, we can go back in time and need to
// acquire the latest upstream tag that can create an event at the given
// tag. We also need to consider that given a delay d and a tag g=(t, n),
Expand Down Expand Up @@ -240,8 +240,8 @@ public:
};
}

auto acquire_tag(const Tag& tag, std::unique_lock<std::mutex>& lock,
const std::function<bool(void)>& abort_waiting) -> bool override {
auto acquire_tag(const Tag& tag, std::unique_lock<std::mutex>& lock, const std::function<bool(void)>& abort_waiting)
-> bool override {
this->log_.debug() << "downstream tries to acquire tag " << tag;
return PhysicalTimeBarrier::acquire_tag(tag, lock, this->environment()->scheduler(), abort_waiting);
}
Expand Down
13 changes: 3 additions & 10 deletions include/reactor-cpp/environment.hh
Original file line number Diff line number Diff line change
Expand Up @@ -75,31 +75,25 @@ private:
Graph<BasePort*, ConnectionProperties> graph_{};
Graph<BasePort*, ConnectionProperties> optimized_graph_{};


std::mutex shutdown_mutex_{};

auto startup(const TimePoint& start_time) -> std::thread;

public:
//TODO: fix visebility
// TODO: fix visebility
void calculate_indexes();
void build_dependency_graph(Reactor* reactor);
void clear_dependency_graph();


explicit Environment(unsigned int num_workers, bool fast_fwd_execution = default_fast_fwd_execution,
const Duration& timeout = Duration::max());
explicit Environment(const std::string& name, Environment* containing_environment);

auto name() -> const std::string& { return name_; }

void start_mutation() {
phase_ = Phase::Mutation;
}
void start_mutation() { phase_ = Phase::Mutation; }

void stop_mutation() {
phase_ = Phase::Execution;
}
void stop_mutation() { phase_ = Phase::Execution; }

// this method draw a connection between two graph elements with some properties
template <class T> void draw_connection(Port<T>& source, Port<T>& sink, ConnectionProperties properties) {
Expand All @@ -112,7 +106,6 @@ public:
auto properties = graph_.remove_edge(source, sink);
} else {
return top_environment_->remove_connection(source, sink);

}
}

Expand Down
20 changes: 9 additions & 11 deletions include/reactor-cpp/graph.hh
Original file line number Diff line number Diff line change
Expand Up @@ -54,24 +54,22 @@ public:
std::vector<std::pair<P, E>> edges{std::make_pair(properties, destination)};
graph_[source] = edges;
} else {
auto &edges = graph_[source];
auto duplicate = std::find_if(edges.begin(), edges.end(),
[&](const std::pair<P, E>& edge) {
return edge.first == properties && edge.second == destination;
});
if (duplicate == edges.end()) {
graph_[source].emplace_back(properties, destination);
}
auto& edges = graph_[source];
auto duplicate = std::find_if(edges.begin(), edges.end(), [&](const std::pair<P, E>& edge) {
return edge.first == properties && edge.second == destination;
});
if (duplicate == edges.end()) {
graph_[source].emplace_back(properties, destination);
}
}
}

auto remove_edge(E source, E destinations) noexcept -> std::optional<P> {
if (graph_.find(source) == std::end(graph_)) {
return std::nullopt;
} else {
auto conns = std::find_if(std::begin(graph_[source]), std::end(graph_[source]), [destinations](auto val) {
return val.second == destinations;
});
auto conns = std::find_if(std::begin(graph_[source]), std::end(graph_[source]),
[destinations](auto val) { return val.second == destinations; });

if (conns != std::end(graph_[source])) {
graph_[source].erase(conns);
Expand Down
5 changes: 2 additions & 3 deletions include/reactor-cpp/impl/port_impl.hh
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@
#ifndef REACTOR_CPP_IMPL_PORT_IMPL_HH
#define REACTOR_CPP_IMPL_PORT_IMPL_HH

#include "reactor-cpp/port.hh"
#include "reactor-cpp/reactor.hh"
#include "reactor-cpp/assert.hh"
#include "reactor-cpp/environment.hh"

#include "reactor-cpp/port.hh"
#include "reactor-cpp/reactor.hh"

namespace reactor {

Expand Down
18 changes: 9 additions & 9 deletions include/reactor-cpp/multiport.hh
Original file line number Diff line number Diff line change
Expand Up @@ -48,32 +48,31 @@ protected:

void register_port(BasePort& port, size_t idx);


public:
explicit BaseMultiport(const std::string& name) : multiport_name_(name) {};
explicit BaseMultiport(const std::string& name)
: multiport_name_(name){};
~BaseMultiport() = default;
auto name() const -> std::string {
return multiport_name_;
}
auto name() const -> std::string { return multiport_name_; }
};

template <class T>
class MutationChangeMultiportSize;
template <class T> class MutationChangeMultiportSize;

template <class T, class A = std::allocator<T>>
class Multiport : public BaseMultiport { // NOLINT cppcoreguidelines-special-member-functions
protected:
std::vector<T> ports_{}; // NOLINT cppcoreguidelines-non-private-member-variables-in-classes

friend MutationChangeMultiportSize<T>;

public:
using value_type = typename A::value_type;
using size_type = typename A::size_type;

using iterator = typename std::vector<T>::iterator;
using const_iterator = typename std::vector<T>::const_iterator;

explicit Multiport(const std::string& name) noexcept : BaseMultiport(name) {};
explicit Multiport(const std::string& name) noexcept
: BaseMultiport(name){};
~Multiport() noexcept = default;

auto operator==(const Multiport& other) const noexcept -> bool {
Expand Down Expand Up @@ -106,7 +105,8 @@ public:

template <class T, class A = std::allocator<T>> class ModifableMultiport : public Multiport<T, A> {
public:
ModifableMultiport(const std::string& name) : Multiport<T, A>(name) {}
ModifableMultiport(const std::string& name)
: Multiport<T, A>(name) {}

void reserve(std::size_t size) noexcept {
this->ports_.reserve(size);
Expand Down
6 changes: 3 additions & 3 deletions include/reactor-cpp/mutations.hh
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ enum MutationResult {
class Mutation {
public:
virtual ~Mutation() = default;
virtual auto run() -> MutationResult = 0 ;
virtual auto run() -> MutationResult = 0;
virtual auto rollback() -> MutationResult = 0;
};

}
} // namespace reactor

#endif //MUTATIONS_HH
#endif // MUTATIONS_HH
22 changes: 12 additions & 10 deletions include/reactor-cpp/mutations/bank.hh
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,14 @@

#include <vector>

#include "../reactor.hh"
#include "../mutations.hh"
#include "../reactor.hh"

namespace reactor {
class Reactor;
class Environment;

template<class T>
class MutationChangeBankSize : public reactor::Mutation {
private:
template <class T> class MutationChangeBankSize : public reactor::Mutation {
std::vector<T>* bank_ = nullptr;
std::size_t desired_size_ = 0;
std::size_t size_before_application_ = 0;
Expand All @@ -26,14 +24,18 @@ private:
void change_size(std::size_t);

public:
MutationChangeBankSize(std::vector<T>* bank, Reactor* reactor, std::size_t size, std::function<T(Reactor* reactor, std::size_t index)>);
MutationChangeBankSize(std::vector<T>* bank, Reactor* reactor, std::size_t size,
std::function<T(Reactor* reactor, std::size_t index)>);
MutationChangeBankSize() = default;
explicit MutationChangeBankSize(const std::vector<T>& other) : bank_(other.bank_), desired_size_(other.desired_size_), size_before_application_(other.size_before_application_) {}
explicit MutationChangeBankSize(const std::vector<T>& other)
: bank_(other.bank_)
, desired_size_(other.desired_size_)
, size_before_application_(other.size_before_application_) {}
~MutationChangeBankSize() override = default;

auto run() -> reactor::MutationResult override;
auto rollback() -> reactor::MutationResult override;
auto run() -> MutationResult override;
auto rollback() -> MutationResult override;
};
}
} // namespace reactor

#endif //MUTATION_BANK_HH
#endif // MUTATION_BANK_HH
13 changes: 8 additions & 5 deletions include/reactor-cpp/mutations/connection.hh
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ namespace reactor {
class Reactor;
class Environment;

template<class A, class B>
class MutationAddConnection : public Mutation {
template <class A, class B> class MutationAddConnection : public Mutation {
private:
A* source_;
B* sink_;
Expand All @@ -21,13 +20,17 @@ private:

public:
MutationAddConnection(A* source, B* sink, Reactor* reactor);
MutationAddConnection(const MutationAddConnection& other) : source_(other.source_), sink_(other.sink_), connection_(other.connection_), reactor_(other.reactor_) {}
MutationAddConnection(const MutationAddConnection& other)
: source_(other.source_)
, sink_(other.sink_)
, connection_(other.connection_)
, reactor_(other.reactor_) {}
MutationAddConnection() = default;
~MutationAddConnection() override = default;

auto run() -> MutationResult override;
auto rollback() -> MutationResult override;
};
}
} // namespace reactor

#endif //MUTATION_CONNECTION_HH
#endif // MUTATION_CONNECTION_HH
18 changes: 9 additions & 9 deletions include/reactor-cpp/mutations/multiport.hh
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,11 @@
#include "../mutations.hh"
#include "../port.hh"


namespace reactor {
class Reactor;
class Environment;

template<class T>
class MutationChangeOutputMultiportSize : public Mutation {
template <class T> class MutationChangeOutputMultiportSize : public Mutation {
private:
ModifableMultiport<Output<T>>* multiport_ = nullptr;
std::set<Reaction*> anti_dependencies_{};
Expand All @@ -28,16 +26,18 @@ private:
void change_size(std::size_t);

public:
MutationChangeOutputMultiportSize(ModifableMultiport<Output<T>>* multiport, Reactor* reactor, std::set<Reaction*>& anti_dependencies, std::size_t size);
MutationChangeOutputMultiportSize(ModifableMultiport<Output<T>>* multiport, Reactor* reactor,
std::set<Reaction*>& anti_dependencies, std::size_t size);
MutationChangeOutputMultiportSize() = default;
MutationChangeOutputMultiportSize(const MutationChangeOutputMultiportSize& other) : multiport_(other.multiport_), desired_size_(other.desired_size_), size_before_application_(other.size_before_application_) {}
MutationChangeOutputMultiportSize(const MutationChangeOutputMultiportSize& other)
: multiport_(other.multiport_)
, desired_size_(other.desired_size_)
, size_before_application_(other.size_before_application_) {}
~MutationChangeOutputMultiportSize() override = default;


auto run() -> MutationResult override;
auto rollback() -> MutationResult override;
};
}

} // namespace reactor

#endif //MUTATION_MULTIPORT_HH
#endif // MUTATION_MULTIPORT_HH
Loading

0 comments on commit 9e1b6ed

Please sign in to comment.