Skip to content

Commit 95c55bf

Browse files
committed
making it working
1 parent e088e96 commit 95c55bf

File tree

10 files changed

+23
-22
lines changed

10 files changed

+23
-22
lines changed

examples/multiport_mutation/load_balancer.hh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ private:
3535

3636
auto antideps = (outbound[0]).anti_dependencies();
3737

38-
MutationChangeOutputMultiportSize change_size{temp, this->reactor_, antideps, new_size};
38+
auto change_size = std::make_shared<MutationChangeOutputMultiportSize<unsigned>>(temp, this->reactor_, antideps, new_size);
3939

40-
add_to_transaction(&change_size);
40+
add_to_transaction(change_size);
4141

4242
commit_transaction();
4343

examples/multiport_mutation/main.cc

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ class Inner: public MutableScope {
3333
std::string __lf_inst_name = "consumer_" + std::to_string(index);
3434
return std::make_unique<Consumer>(__lf_inst_name, reactor->environment(), index);
3535
};
36-
MutationChangeBankSize change_size{&reactor_bank, this->reactor_, new_size, lambda};
36+
auto change_size = std::make_shared<MutationChangeBankSize<std::unique_ptr<Consumer>>>(&reactor_bank, this->reactor_, new_size, lambda);
3737

38-
add_to_transaction(&change_size);
38+
add_to_transaction(change_size);
3939

4040
// old topology
4141
commit_transaction();
@@ -48,9 +48,8 @@ class Inner: public MutableScope {
4848
} else {
4949
std::cout << "load_balancer size:" << load_balancer.size() << " bank size: " << reactor_bank.size() << std::endl;
5050
for (auto i = 0; i < new_size; i++) {
51-
std::cout << "add connection: " << i << std::endl;
52-
MutationAddConnection<Output<unsigned>, Input<unsigned>> add_conn{&load_balancer[i], &reactor_bank[i].get()->in, reactor_};
53-
add_to_transaction(&add_conn);
51+
auto add_conn = std::make_shared<MutationAddConnection<Output<unsigned>, Input<unsigned>>>(&load_balancer[i], &reactor_bank[i].get()->in, reactor_);
52+
add_to_transaction(add_conn);
5453
}
5554
commit_transaction(true);
5655
}

include/reactor-cpp/port.hh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ public:
106106

107107
[[nodiscard]] auto triggers() const noexcept -> const auto& { return triggers_; }
108108
[[nodiscard]] auto dependencies() const noexcept -> const auto& { return dependencies_; }
109-
[[nodiscard]] auto anti_dependencies() const noexcept -> const auto& { return anti_dependencies_; }
109+
[[nodiscard]] auto anti_dependencies() noexcept -> auto& { return anti_dependencies_; } //TODO: make it const again
110110
[[nodiscard]] auto port_type() const noexcept -> PortType { return type_; }
111111

112112
void register_set_callback(const PortCallback& callback);

include/reactor-cpp/scopes.hh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public:
4444
~MutableScope() = default;
4545

4646
void commit_transaction(bool recalculate = false);
47-
void add_to_transaction(Mutation* mutation);
47+
void add_to_transaction(const std::shared_ptr<Mutation>& mutation);
4848

4949
};
5050

include/reactor-cpp/transaction.hh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#define REACTOR_CPP_TRANSACTION_HH
1111

1212
#include <vector>
13+
#include <memory>
1314

1415
#include "mutations.hh"
1516
//#include "reactor.hh"
@@ -22,13 +23,13 @@ class Environment;
2223
class Transaction {
2324
private:
2425
Environment* environment_ = nullptr;
25-
std::vector<Mutation*> mutations_{};
26+
std::vector<std::shared_ptr<Mutation>> mutations_{};
2627

2728
public:
2829
explicit Transaction(Reactor* parent);
2930
~Transaction() = default;
3031

31-
void push_back(Mutation* mutation);
32+
void push_back(const std::shared_ptr<Mutation>& mutation);
3233
auto execute(bool recalculate = false) -> MutationResult;
3334
};
3435
}

lib/mutation/connection.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ template <class A, class B> auto reactor::MutationAddConnection<A, B>::run() ->
1515
reactor_->environment()->draw_connection(source_, sink_, ConnectionProperties{});
1616
sink_->set_inward_binding(source_);
1717
source_->add_outward_binding(sink_);
18-
std::cout << "from: " << source_->fqn() << "(" << source_ << ")"
19-
<< " --> to: " << sink_->fqn() << "(" << sink_ << ")" << std::endl;
18+
//std::cout << "from: " << source_->fqn() << "(" << source_ << ")"
19+
// << " --> to: " << sink_->fqn() << "(" << sink_ << ")" << std::endl;
2020
return Success;
2121
}
2222

lib/mutation/multiport.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ reactor::MutationChangeOutputMultiportSize<T>::MutationChangeOutputMultiportSize
1212
template<class T>
1313
void reactor::MutationChangeOutputMultiportSize<T>::change_size(std::size_t new_size) {
1414
auto current_size = multiport_->size();
15-
std::cout << "scaling from: " << current_size << " to " << new_size << std::endl;
16-
1715
if (current_size >= new_size) {
1816
// downscale
1917

@@ -29,6 +27,8 @@ void reactor::MutationChangeOutputMultiportSize<T>::change_size(std::size_t new_
2927
for (auto* anti_dep : anti_dependencies_) {
3028
anti_dep->clear_antidependencies();
3129
for (auto i = 0; i < new_size; i++) {
30+
31+
multiport_->operator[](i).anti_dependencies().clear();
3232
anti_dep->declare_antidependency(&multiport_->operator[](i));
3333
}
3434
}
@@ -40,12 +40,12 @@ void reactor::MutationChangeOutputMultiportSize<T>::change_size(std::size_t new_
4040
multiport_->emplace_back(port_name_, reactor_);
4141
}
4242

43-
for (auto* anti_dep : anti_dependencies_) {
43+
/*for (auto* anti_dep : anti_dependencies_) {
4444
anti_dep->clear_antidependencies();
4545
for (auto i = 0; i < new_size; i++) {
4646
anti_dep->declare_antidependency(&multiport_->operator[](i));
4747
}
48-
}
48+
}*/
4949

5050

5151
}

lib/reaction.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ void Reaction::declare_dependency(BasePort* port) {
9191
void Reaction::declare_antidependency(BasePort* port) {
9292
reactor_assert(port != nullptr);
9393
reactor_assert(this->environment() == port->environment());
94-
assert_phase(this, Phase::Assembly);
94+
//assert_phase(this, Phase::Assembly);
9595

9696
if (port->is_output()) {
9797
validate(this->container() == port->container(), "Antidependent output ports must belong to the same reactor as "

lib/scopes.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
#include "reactor-cpp/scopes.hh"
44

5-
void reactor::MutableScope::add_to_transaction(Mutation* mutation) {
5+
void reactor::MutableScope::add_to_transaction(const std::shared_ptr<Mutation>& mutation) {
66
transaction_.push_back(mutation);
77
}
88

lib/transaction.cc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
auto reactor::Transaction::execute(bool recalculate) -> MutationResult {
1111

1212
this->environment_->start_mutation();
13-
for (auto *mutation : mutations_) {
13+
for (auto mutation : mutations_) {
1414
mutation->run();
1515
}
1616

@@ -24,10 +24,11 @@ auto reactor::Transaction::execute(bool recalculate) -> MutationResult {
2424
}
2525

2626
this->environment_->stop_mutation();
27+
2728
mutations_.clear();
28-
return Success;
29+
return Success;
2930
}
3031

31-
void reactor::Transaction::push_back(reactor::Mutation* mutation) {
32+
void reactor::Transaction::push_back(const std::shared_ptr<reactor::Mutation>& mutation) {
3233
mutations_.push_back(mutation);
3334
}

0 commit comments

Comments
 (0)