Skip to content

Commit 064a096

Browse files
committed
code cleaning
1 parent 9e1b6ed commit 064a096

File tree

4 files changed

+21
-27
lines changed

4 files changed

+21
-27
lines changed

examples/multiport_mutation/consumer.hh

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,28 +11,27 @@ using namespace reactor;
1111
using namespace std::chrono_literals;
1212

1313
class Consumer : public Reactor {
14-
private:
1514
class Inner: public Scope {
1615
Inner(Reactor* reactor, std::size_t index) : Scope(reactor), index_(index) {}
17-
std::size_t index_;
16+
std::size_t index_ = 0;
1817

19-
[[maybe_unused]] const Inner& __lf_inner = *this;
18+
const Inner& _lf_inner = *this;
2019

21-
void reaction_1([[maybe_unused]] const Input<unsigned>& in) {
22-
std::cout << "consumer: " << index_ << " received value:" << *in.get() << std::endl;
20+
void reaction_1(const Input<unsigned>& in) const {
21+
std::cout << "consumer: " << index_ << " received value:" << *in.get() << '\n';
2322
}
2423

2524
friend Consumer;
2625
};
2726

28-
Inner __lf_inner;
29-
Reaction handle{"handle", 1, this, [this]() { __lf_inner.reaction_1(this->in); }};
27+
Inner _lf_inner;
28+
Reaction handle{"handle", 1, this, [this]() { _lf_inner.reaction_1(this->in); }};
3029
public:
31-
Consumer(const std::string& name, Environment* env, std::size_t index) : Reactor(name, env), __lf_inner(this, index) {
32-
std::cout << "creating instance of consumer" << std::endl;
30+
Consumer(const std::string& name, Environment* env, std::size_t index) : Reactor(name, env), _lf_inner(this, index) {
31+
std::cout << "creating instance of consumer" << '\n';
3332
}
3433
~Consumer() override {
35-
std::cout << "Consumer Object is deleted" << std::endl;
34+
std::cout << "Consumer Object is deleted" << '\n';
3635
};
3736

3837
Input<unsigned> in{"in", this};

examples/multiport_mutation/load_balancer.hh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class LoadBalancer : public Reactor {
1717
private:
1818
class Inner: public MutableScope {
1919
Inner(Reactor* reactor) : MutableScope(reactor) {}
20-
[[maybe_unused]] const Inner& __lf_inner = *this;
20+
const Inner& __lf_inner = *this;
2121

2222
// reaction bodies
2323
void reaction_1(const Input<unsigned>& inbound, LogicalAction<unsigned>& scale_action, Multiport<Output<unsigned>>& outbound) {

examples/multiport_mutation/main.cc

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,40 +21,33 @@ class Deployment : public Reactor {
2121

2222
class Inner: public MutableScope {
2323
int state = 0;
24-
[[maybe_unused]] const Inner& __lf_inner = *this;
24+
const Inner& __lf_inner = *this;
2525
public:
2626

2727
Inner(Reactor* reactor) : MutableScope(reactor) {}
2828
void reaction_1(const Input<unsigned>& scale, std::vector<std::unique_ptr<Consumer>>& reactor_bank, ModifableMultiport<Output<unsigned>>& load_balancer) {
2929
std::size_t new_size = *scale.get();
3030
std::size_t old_size = reactor_bank.size();
3131

32-
std::function<std::unique_ptr<Consumer>(Reactor*, std::size_t)> lambda = [](Reactor* reactor, std::size_t index) {
32+
std::function lambda = [](Reactor* reactor, std::size_t index) {
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+
3637
auto change_size = std::make_shared<MutationChangeBankSize<std::unique_ptr<Consumer>>>(&reactor_bank, this->reactor_, new_size, lambda);
3738

3839
add_to_transaction(change_size);
3940

40-
// old topology
4141
commit_transaction();
42-
// new topology
43-
44-
if (old_size > new_size) {
4542

46-
for (auto i = 0; i < old_size - new_size; i++) {
47-
}
48-
} else {
49-
std::cout << "load_balancer size:" << load_balancer.size() << " bank size: " << reactor_bank.size() << std::endl;
43+
if (old_size < new_size) {
5044
for (auto i = 0; i < new_size; i++) {
5145
auto add_conn = std::make_shared<MutationAddConnection<Output<unsigned>, Input<unsigned>>>(&load_balancer[i], &reactor_bank[i].get()->in, reactor_);
5246
add_to_transaction(add_conn);
5347
}
54-
commit_transaction(true);
5548
}
5649

57-
std::cout << "new bank size:" << reactor_bank.size() << std::endl;
50+
commit_transaction(true);
5851
}
5952

6053
friend LoadBalancer;

examples/multiport_mutation/producer.hh

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,14 @@ private:
1616
Reaction r_timer{"r_timer", 1, this, [this]() { __lf_inner.reaction_1(this->value);}};
1717

1818
class Inner: public Scope {
19-
unsigned itr = 0;
20-
[[maybe_unused]] const Inner& __lf_inner = *this;
19+
unsigned int counter_ = 0;
20+
const Inner& __lf_inner = *this;
21+
2122
void reaction_1([[maybe_unused]] Output<unsigned>& out) {
22-
std::cout << "producing value:" << itr << std::endl;
23-
out.set(itr++);
23+
std::cout << "producing value:" << counter_ << std::endl;
24+
out.set(counter_++);
2425
}
26+
2527
explicit Inner(Reactor* reactor) : Scope(reactor) {}
2628

2729
friend Producer;

0 commit comments

Comments
 (0)