Skip to content

Commit 5927709

Browse files
committed
ReactionChamber renaming, fix for gcc < 13 compiler versions
1 parent 5e1ecf2 commit 5927709

File tree

4 files changed

+62
-31
lines changed

4 files changed

+62
-31
lines changed

examples/sdk-WorkersParams/main.cc

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -160,13 +160,11 @@ class Worker : public Reactor {
160160
};
161161

162162
PublishParameters parameters;
163-
const Duration &processing_delay = parameters.processing_delay.value;
164-
165-
class Internals : public ReactionInternals<Worker, PublishParameters> {
163+
class Chamber : public ReactionChamber<Worker, PublishParameters> {
166164
const Duration &processing_delay = parameters.processing_delay.value;
167165
public:
168-
Internals(Reactor *reactor, PublishParameters &params)
169-
: ReactionInternals<Worker, PublishParameters>(reactor, params) {}
166+
Chamber(Reactor *reactor, PublishParameters &params)
167+
: ReactionChamber<Worker, PublishParameters>(reactor, params) {}
170168

171169
void add_reactions(Worker *reactor) override {
172170
reaction("reaction_1").
@@ -220,7 +218,7 @@ class Worker : public Reactor {
220218

221219

222220
};
223-
Internals reaction_internals{this, parameters};
221+
Chamber reaction_chamber{this, parameters};
224222

225223
public:
226224
Worker(const std::string &name, Environment *env, Parameters &&param)
@@ -260,11 +258,10 @@ class Pool : public Reactor {
260258
ReactorBank<Worker> workers{"workers", this};
261259
std::unique_ptr<Relay> relay;
262260

263-
class Internals : public ReactionInternals<Pool, PublishParameters> {
264-
const int &n_workers = parameters.n_workers.value;
261+
class Chamber : public ReactionChamber<Pool, PublishParameters> {
265262
public:
266-
Internals(Reactor *reactor, PublishParameters &params)
267-
: ReactionInternals<Pool, PublishParameters>(reactor, params) {}
263+
Chamber(Reactor *reactor, PublishParameters &params)
264+
: ReactionChamber<Pool, PublishParameters>(reactor, params) {}
268265

269266
void add_reactions(Pool *reactor) override {
270267
reaction("reaction_1").
@@ -293,7 +290,7 @@ class Pool : public Reactor {
293290

294291
};
295292

296-
Internals reaction_internals{this, parameters};
293+
Chamber reaction_chamber{this, parameters};
297294

298295
public:
299296
Pool(const std::string &name, Environment *env, Parameters &&param)
@@ -333,21 +330,20 @@ class Tasks : public Reactor {
333330

334331
private:
335332
Parameters parameters;
336-
const int &n_tasks = parameters.n_tasks;
337333
const int &n_pools = parameters.n_pools;
338334

339335
LogicalAction<int> sch{"sch", this};
340336

341-
class Internals : public ReactionInternals<Tasks, Parameters> {
337+
class Chamber : public ReactionChamber<Tasks, Parameters> {
342338
const int &n_tasks = parameters.n_tasks;
343339
const int &n_pools = parameters.n_pools;
344340

345341
int req_itr = 0;
346342
int rsp_itr = 0;
347343
bool *busy = 0;
348344
public:
349-
Internals(Reactor *reactor, Parameters &params)
350-
: ReactionInternals<Tasks, Parameters>(reactor, params) {}
345+
Chamber(Reactor *reactor, Parameters &params)
346+
: ReactionChamber<Tasks, Parameters>(reactor, params) {}
351347

352348
void add_reactions(Tasks *reactor) override {
353349
reaction("reaction_1").
@@ -457,7 +453,7 @@ class Tasks : public Reactor {
457453
}
458454
};
459455

460-
Internals reaction_internals{this, parameters};
456+
Chamber reaction_chamber{this, parameters};
461457

462458
public:
463459
Tasks(const std::string &name, Environment *env, Parameters &&param)

examples/sdk-hello/main.cc

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@ class Hello : public Reactor {
1111

1212
Timer timer{"timer", this};
1313

14-
REACTION_SCOPE_START(Hello, Parameters)
14+
class Chamber : public ReactionChamber<Hello, Parameters> {
15+
public:
16+
Chamber(Reactor *reactor, Parameters &params)
17+
: ReactionChamber<Hello, Parameters>(reactor, params) {}
18+
private:
1519

1620
void terminate(Shutdown& shutdown) {
1721
std::cout << "(" << get_elapsed_logical_time().count() << ", " << get_microstep() << ") physical_time:" << get_elapsed_physical_time().count()
@@ -36,8 +40,8 @@ class Hello : public Reactor {
3640
effects().
3741
function(pass_function(terminate));
3842
}
39-
40-
REACTION_SCOPE_END(this, parameters)
43+
};
44+
Chamber reaction_chamber{this, parameters};
4145

4246
public:
4347
Hello(const std::string &name, Environment *env)

include/reactor-sdk/Misc.hh

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ using LogicalAction = reactor::LogicalAction<T>;
1313
using Startup = reactor::StartupTrigger;
1414
using Shutdown = reactor::ShutdownTrigger;
1515

16-
using Duration = std::chrono::nanoseconds;
16+
using Duration = reactor::Duration;
17+
using TimePoint = reactor::TimePoint;
1718

1819
#define select_default(obj) &obj[0]
1920

@@ -77,5 +78,30 @@ public:
7778
Timer(Timer&&) noexcept = default;
7879
};
7980

81+
inline auto operator<<(std::ostream& os, Duration dur) -> std::ostream& {
82+
os << dur.count() << " nsecs";
83+
return os;
84+
}
85+
86+
constexpr std::size_t TIME_TO_STR_BUFFER_SIZE_{20};
87+
constexpr std::size_t NANOSECONDS_IN_ONE_SECOND_{1'000'000'000UL};
88+
constexpr std::size_t NANOSECOND_DIGITS_{9};
89+
90+
inline auto operator<<(std::ostream& os, TimePoint tp) -> std::ostream& {
91+
std::array<char, TIME_TO_STR_BUFFER_SIZE_> buf{};
92+
time_t time =
93+
std::chrono::system_clock::to_time_t(std::chrono::time_point_cast<std::chrono::system_clock::duration>(tp));
94+
auto res = std::strftime(buf.data(), sizeof(buf), "%Y-%m-%d %H:%M:%S", std::localtime(&time));
95+
auto epoch = std::chrono::duration_cast<Duration>(tp.time_since_epoch());
96+
97+
if (res != 0) {
98+
os << buf.data() << '.' << std::setw(NANOSECOND_DIGITS_) << std::setfill('0')
99+
<< epoch.count() % NANOSECONDS_IN_ONE_SECOND_;
100+
} else {
101+
os << "[INVALID TIME]";
102+
}
103+
104+
return os;
105+
}
80106

81107
} // namespace sdk

include/reactor-sdk/Reaction.hh

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ struct is_specialization<Template<Args...>, Template> : std::true_type
2323
template <typename T, template <typename...> class Template>
2424
inline constexpr bool is_specialization_v = is_specialization<T, Template>::value;
2525

26-
26+
// fix for gcc < 13
27+
template <typename T>
28+
constexpr bool templated_false = false;
2729

2830
template <typename InputTuple, typename DependencyTuple, typename OutputTuple>
2931
class ReactionOutput: public ReactionBase
@@ -113,7 +115,7 @@ public:
113115
}
114116

115117
// template <typename ReactorType, typename ParameterType>
116-
// friend class ReactionInternals;
118+
// friend class ReactionChamber;
117119
};
118120

119121
template <typename Fn, typename InputTuple, typename DependencyTuple, typename OutputTuple>
@@ -204,7 +206,7 @@ private:
204206
}
205207
else
206208
{
207-
static_assert(false, "Unsupported trigger type");
209+
static_assert(templated_false<Trigger>, "Unsupported trigger type");
208210
}
209211
}
210212

@@ -219,6 +221,9 @@ private:
219221
outputs);
220222
}
221223

224+
template <typename Reaction>
225+
void set_output_triggers(std::unique_ptr<Reaction>& reaction, const std::tuple<>& outputs) {}
226+
222227
public:
223228
Reaction(std::string name, Reactor *parent, InputTuple inputs, DependencyTuple deps, OutputTuple outputs, Fn func)
224229
: ReactionBase(name, parent), input_triggers(std::move(inputs)), dependencies(std::move(deps)), output_triggers(std::move(outputs)), user_function(std::forward<Fn>(func)) { /* std::cout << "Creating Reaction\n"; */ }
@@ -274,12 +279,12 @@ public:
274279
};
275280

276281
template <typename ReactorType>
277-
class ReactionInternalsParameterless : public ReactionBase {
282+
class ReactionChamberParameterless : public ReactionBase {
278283
ReactorType *reactor_;
279284
protected:
280285
const size_t &bank_index = reactor_->bank_index;
281286
public:
282-
ReactionInternalsParameterless(Reactor *owner)
287+
ReactionChamberParameterless(Reactor *owner)
283288
: ReactionBase("reaction-internals-parameterless", owner), reactor_((ReactorType*) owner) {
284289
reactor_->add_reaction_internals(this);
285290
}
@@ -306,14 +311,14 @@ public:
306311
};
307312

308313
template <typename ReactorType, typename ParameterType>
309-
class ReactionInternals : public ReactionBase {
314+
class ReactionChamber : public ReactionBase {
310315
ReactorType *reactor_;
311316

312317
protected:
313318
const ParameterType &parameters;
314319
const size_t &bank_index = reactor_->bank_index;
315320
public:
316-
ReactionInternals(Reactor *owner, ParameterType &param)
321+
ReactionChamber(Reactor *owner, ParameterType &param)
317322
: ReactionBase("reaction-internals", owner), reactor_((ReactorType*) owner), parameters(param) {
318323
reactor_->add_reaction_internals(this);
319324
}
@@ -340,21 +345,21 @@ public:
340345
};
341346

342347
#define REACTION_SCOPE_START(ReactorType, ParamType) \
343-
class Internals : public ReactionInternals<ReactorType, ParamType> { \
348+
class Internals : public ReactionChamber<ReactorType, ParamType> { \
344349
public: \
345350
Internals(Reactor *reactor, ParamType &params) \
346-
: ReactionInternals<ReactorType, ParamType>(reactor, params) {} \
351+
: ReactionChamber<ReactorType, ParamType>(reactor, params) {} \
347352
private:
348353

349354
#define REACTION_SCOPE_END(reactor, param) \
350355
}; \
351356
Internals reaction_internals{reactor, param};
352357

353358
#define REACTION_SCOPE_START_NO_PARAMS(ReactorType) \
354-
class Internals : public ReactionInternalsParameterless<ReactorType> { \
359+
class Internals : public ReactionChamberParameterless<ReactorType> { \
355360
public: \
356361
Internals(Reactor *reactor) \
357-
: ReactionInternalsParameterless<ReactorType>(reactor) {} \
362+
: ReactionChamberParameterless<ReactorType>(reactor) {} \
358363
private:
359364

360365
#define REACTION_SCOPE_END_NO_PARAMS(reactor) \

0 commit comments

Comments
 (0)