Skip to content

Commit d590c81

Browse files
committed
keep track of input actions in the environment
Currently, the only action type that is an input action is a physical action. Later we will add enclave and federate connections.
1 parent e5d7cfd commit d590c81

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

include/reactor-cpp/action.hh

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
#ifndef REACTOR_CPP_ACTION_HH
1010
#define REACTOR_CPP_ACTION_HH
1111

12+
#include "environment.hh"
13+
#include "fwd.hh"
1214
#include "logical_time.hh"
1315
#include "reactor.hh"
1416
#include "value_ptr.hh"
@@ -37,6 +39,12 @@ protected:
3739
: ReactorElement(name, ReactorElement::Type::Action, container)
3840
, min_delay_(min_delay)
3941
, logical_(logical) {}
42+
BaseAction(const std::string& name, Environment* environment, bool logical, Duration min_delay)
43+
: ReactorElement(name, ReactorElement::Type::Action, environment)
44+
, min_delay_(min_delay)
45+
, logical_(logical) {
46+
environment->register_input_action(this);
47+
}
4048

4149
public:
4250
[[nodiscard]] auto inline triggers() const noexcept -> const auto& { return triggers_; }
@@ -63,6 +71,8 @@ protected:
6371

6472
Action(const std::string& name, Reactor* container, bool logical, Duration min_delay)
6573
: BaseAction(name, container, logical, min_delay) {}
74+
Action(const std::string& name, Environment* environment, bool logical, Duration min_delay)
75+
: BaseAction(name, environment, logical, min_delay) {}
6676

6777
public:
6878
// Normally, we should lock the mutex while moving to make this
@@ -107,6 +117,8 @@ template <> class Action<void> : public BaseAction {
107117
protected:
108118
Action(const std::string& name, Reactor* container, bool logical, Duration min_delay)
109119
: BaseAction(name, container, logical, min_delay) {}
120+
Action(const std::string& name, Environment* environment, bool logical, Duration min_delay)
121+
: BaseAction(name, environment, logical, min_delay) {}
110122

111123
public:
112124
template <class Dur = Duration> void schedule(Dur delay = Dur::zero());
@@ -118,7 +130,11 @@ public:
118130
template <class T> class PhysicalAction : public Action<T> {
119131
public:
120132
PhysicalAction(const std::string& name, Reactor* container)
121-
: Action<T>(name, container, false, Duration::zero()) {}
133+
: Action<T>(name, container, false, Duration::zero()) {
134+
// all physical actions act as input actions to the program as they can be
135+
// scheduled from external threads
136+
container->environment()->register_input_action(this);
137+
}
122138
};
123139

124140
template <class T> class LogicalAction : public Action<T> {

include/reactor-cpp/environment.hh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <string>
1414
#include <vector>
1515

16+
#include "fwd.hh"
1617
#include "reactor-cpp/logging.hh"
1718
#include "reactor-cpp/time.hh"
1819
#include "reactor.hh"
@@ -40,6 +41,8 @@ private:
4041
const bool fast_fwd_execution_{default_fast_fwd_execution};
4142

4243
std::set<Reactor*> top_level_reactors_{};
44+
/// Set of actions that act as an input to the reactor program in this environment
45+
std::set<BaseAction*> input_actions_{};
4346
std::set<Reaction*> reactions_{};
4447
std::vector<Dependency> dependencies_{};
4548

@@ -71,6 +74,7 @@ public:
7174
auto name() -> const std::string& { return name_; }
7275

7376
void register_reactor(Reactor* reactor);
77+
void register_input_action(BaseAction* action);
7478
void assemble();
7579
auto startup() -> std::thread;
7680
void sync_shutdown();

lib/environment.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,12 @@ void Environment::register_reactor(Reactor* reactor) {
5252
reactor_assert(top_level_reactors_.insert(reactor).second);
5353
}
5454

55+
void Environment::register_input_action(BaseAction* action) {
56+
reactor_assert(action != nullptr);
57+
validate(this->phase() == Phase::Construction, "Input actions may only be registered during construction phase!");
58+
reactor_assert(input_actions_.insert(action).second);
59+
}
60+
5561
void recursive_assemble(Reactor* container) { // NOLINT
5662
container->assemble();
5763
for (auto* reactor : container->reactors()) {

0 commit comments

Comments
 (0)