Skip to content

Commit c897cbd

Browse files
committed
Re-implemented how continuations are handled on transaction level.
1 parent f4d022f commit c897cbd

7 files changed

Lines changed: 663 additions & 212 deletions

File tree

include/react/Domain.h

Lines changed: 67 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -97,35 +97,36 @@ using REACT_IMPL::EPropagationMode;
9797
///////////////////////////////////////////////////////////////////////////////////////////////////
9898
class TransactionStatus
9999
{
100-
using StateT = REACT_IMPL::AsyncState;
100+
using StateT = REACT_IMPL::SharedWaitingState;
101+
using PtrT = REACT_IMPL::WaitingStatePtrT;
101102

102103
public:
103104
TransactionStatus() :
104-
state_( std::make_shared<StateT>() )
105+
statePtr_( StateT::Create() )
105106
{}
106107

107108
TransactionStatus(const TransactionStatus&) = default;
108109

109110
TransactionStatus(TransactionStatus&& other) :
110-
state_( std::move(other.state_) )
111+
statePtr_( std::move(other.statePtr_) )
111112
{}
112113

113114
TransactionStatus& operator=(const TransactionStatus&) = default;
114115

115116
TransactionStatus& operator=(TransactionStatus&& other)
116117
{
117-
state_ = std::move(other.state_);
118+
statePtr_ = std::move(other.statePtr_);
118119
return *this;
119120
}
120121

121122
inline void Wait()
122123
{
123-
assert(state_.get() != nullptr);
124-
state_->Wait();
124+
assert(statePtr_.Get() != nullptr);
125+
statePtr_->Wait();
125126
}
126127

127128
private:
128-
std::shared_ptr<StateT> state_;
129+
PtrT statePtr_;
129130

130131
template <typename D, typename F>
131132
friend void AsyncTransaction(TransactionStatus& status, F&& func);
@@ -241,17 +242,31 @@ template
241242
typename S,
242243
typename FIn
243244
>
244-
auto MakeContinuation(const Signal<D,S>& trigger, FIn&& func)
245+
auto MakeContinuation(TurnFlagsT flags, const Signal<D,S>& trigger, FIn&& func)
245246
-> Continuation<D,DOut>
246247
{
247-
static_assert(DOut::is_concurrent, "MakeContinuation requires concurrent target domain.");
248+
static_assert(DOut::is_concurrent,
249+
"MakeContinuation requires support for concurrent input to target domain.");
248250

249251
using REACT_IMPL::SignalContinuationNode;
250252
using F = typename std::decay<FIn>::type;
251253

252254
return Continuation<D,DOut>(
253255
std::make_shared<SignalContinuationNode<D,DOut,S,F>>(
254-
trigger.NodePtr(), std::forward<FIn>(func)));
256+
flags, trigger.NodePtr(), std::forward<FIn>(func)));
257+
}
258+
259+
template
260+
<
261+
typename D,
262+
typename DOut = D,
263+
typename S,
264+
typename FIn
265+
>
266+
auto MakeContinuation(const Signal<D,S>& trigger, FIn&& func)
267+
-> Continuation<D,DOut>
268+
{
269+
return MakeContinuation<D,DOut>(0, trigger, std::forward<FIn>(func));
255270
}
256271

257272
///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -264,17 +279,31 @@ template
264279
typename E,
265280
typename FIn
266281
>
267-
auto MakeContinuation(const Events<D,E>& trigger, FIn&& func)
282+
auto MakeContinuation(TurnFlagsT flags, const Events<D,E>& trigger, FIn&& func)
268283
-> Continuation<D,DOut>
269284
{
270-
static_assert(DOut::is_concurrent, "MakeContinuation requires concurrent target domain.");
285+
static_assert(DOut::is_concurrent,
286+
"MakeContinuation requires support for concurrent input to target domain.");
271287

272288
using REACT_IMPL::EventContinuationNode;
273289
using F = typename std::decay<FIn>::type;
274290

275291
return Continuation<D,DOut>(
276292
std::make_shared<EventContinuationNode<D,DOut,E,F>>(
277-
trigger.NodePtr(), std::forward<FIn>(func)));
293+
flags, trigger.NodePtr(), std::forward<FIn>(func)));
294+
}
295+
296+
template
297+
<
298+
typename D,
299+
typename DOut = D,
300+
typename E,
301+
typename FIn
302+
>
303+
auto MakeContinuation(const Events<D,E>& trigger, FIn&& func)
304+
-> Continuation<D,DOut>
305+
{
306+
return MakeContinuation<D,DOut>(0, trigger, std::forward<FIn>(func));
278307
}
279308

280309
///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -288,18 +317,20 @@ template
288317
typename FIn,
289318
typename ... TDepValues
290319
>
291-
auto MakeContinuation(const Events<D,E>& trigger,
320+
auto MakeContinuation(TurnFlagsT flags, const Events<D,E>& trigger,
292321
const SignalPack<D,TDepValues...>& depPack, FIn&& func)
293322
-> Continuation<D,DOut>
294323
{
295-
static_assert(DOut::is_concurrent, "MakeContinuation requires concurrent target domain.");
324+
static_assert(DOut::is_concurrent,
325+
"MakeContinuation requires support for concurrent input to target domain.");
296326

297327
using REACT_IMPL::SyncedContinuationNode;
298328
using F = typename std::decay<FIn>::type;
299329

300330
struct NodeBuilder_
301331
{
302-
NodeBuilder_(const Events<D,E>& trigger, FIn&& func) :
332+
NodeBuilder_(TurnFlagsT flags, const Events<D,E>& trigger, FIn&& func) :
333+
MyFlags( flags ),
303334
MyTrigger( trigger ),
304335
MyFunc( std::forward<FIn>(func) )
305336
{}
@@ -309,19 +340,36 @@ auto MakeContinuation(const Events<D,E>& trigger,
309340
{
310341
return Continuation<D,DOut>(
311342
std::make_shared<SyncedContinuationNode<D,DOut,E,F,TDepValues...>>(
343+
MyFlags,
312344
MyTrigger.NodePtr(),
313345
std::forward<FIn>(MyFunc), deps.NodePtr() ...));
314346
}
315347

348+
TurnFlagsT MyFlags;
316349
const Events<D,E>& MyTrigger;
317350
FIn MyFunc;
318351
};
319352

320353
return REACT_IMPL::apply(
321-
NodeBuilder_( trigger, std::forward<FIn>(func) ),
354+
NodeBuilder_( flags, trigger, std::forward<FIn>(func) ),
322355
depPack.Data);
323356
}
324357

358+
template
359+
<
360+
typename D,
361+
typename DOut = D,
362+
typename E,
363+
typename FIn,
364+
typename ... TDepValues
365+
>
366+
auto MakeContinuation(const Events<D,E>& trigger,
367+
const SignalPack<D,TDepValues...>& depPack, FIn&& func)
368+
-> Continuation<D,DOut>
369+
{
370+
return MakeContinuation<D,DOut>(0, trigger, depPack, std::forward<FIn>(func));
371+
}
372+
325373
///////////////////////////////////////////////////////////////////////////////////////////////
326374
/// DoTransaction
327375
///////////////////////////////////////////////////////////////////////////////////////////////
@@ -370,7 +418,7 @@ void AsyncTransaction(TransactionStatus& status, F&& func)
370418
using REACT_IMPL::DomainSpecificInputManager;
371419

372420
DomainSpecificInputManager<D>::Instance()
373-
.AsyncTransaction(0, status.state_, std::forward<F>(func));
421+
.AsyncTransaction(0, status.statePtr_, std::forward<F>(func));
374422
}
375423

376424
template <typename D, typename F>
@@ -380,7 +428,7 @@ void AsyncTransaction(TurnFlagsT flags, TransactionStatus& status, F&& func)
380428

381429
using REACT_IMPL::DomainSpecificInputManager;
382430
DomainSpecificInputManager<D>::Instance()
383-
.AsyncTransaction(flags, status.state_, std::forward<F>(func));
431+
.AsyncTransaction(flags, status.statePtr_, std::forward<F>(func));
384432
}
385433

386434
/******************************************/ REACT_END /******************************************/

0 commit comments

Comments
 (0)