1313#include " react/common/Concurrency.h"
1414
1515// //////////////////////////////////////////////////////////////////////////////////////
16- REACT_BEGIN
17-
18- enum class ETransactionMode
19- {
20- none,
21- exclusive
22- };
23-
24- REACT_END
25-
2616REACT_IMPL_BEGIN
2717
2818// //////////////////////////////////////////////////////////////////////////////////////
@@ -55,6 +45,9 @@ struct IReactiveEngine
5545 void OnNodeIdlePulse (NodeInterface& node, TurnInterface& turn) {}
5646
5747 void OnNodeShift (NodeInterface& node, NodeInterface& oldParent, NodeInterface& newParent, TurnInterface& turn) {}
48+
49+ template <typename F>
50+ bool TryMerge (F&& f) { return false ; }
5851};
5952
6053// //////////////////////////////////////////////////////////////////////////////////////
@@ -100,20 +93,20 @@ class TurnBase
10093};
10194
10295// //////////////////////////////////////////////////////////////////////////////////////
103- // / ExclusiveTurnManager
96+ // / TurnQueueManager
10497// //////////////////////////////////////////////////////////////////////////////////////
105- class ExclusiveTurnManager
98+ class TurnQueueManager
10699{
107100public:
108- class ExclusiveTurn
101+ class QueueEntry
109102 {
110103 public:
111- explicit ExclusiveTurn (TurnFlagsT flags) :
104+ explicit QueueEntry (TurnFlagsT flags) :
112105 isMergeable_{ (flags & enable_input_merging) != 0 }
113106 {
114107 }
115108
116- inline void Append (ExclusiveTurn & tr)
109+ inline void Append (QueueEntry & tr)
117110 {
118111 successor_ = &tr;
119112 tr.blockCondition_ .Block ();
@@ -158,7 +151,7 @@ class ExclusiveTurnManager
158151 using MergedDataVectT = std::vector<std::pair<std::function<void ()>,BlockingCondition*>>;
159152
160153 bool isMergeable_;
161- ExclusiveTurn* successor_ = nullptr ;
154+ QueueEntry* successor_ = nullptr ;
162155 MergedDataVectT merged_;
163156 BlockingCondition blockCondition_;
164157 };
@@ -183,7 +176,7 @@ class ExclusiveTurnManager
183176 return merged;
184177 }
185178
186- inline void StartTurn (ExclusiveTurn & turn)
179+ inline void StartTurn (QueueEntry & turn)
187180 {
188181 {// seqMutex_
189182 SeqMutexT::scoped_lock lock (seqMutex_);
@@ -197,7 +190,7 @@ class ExclusiveTurnManager
197190 turn.WaitForUnblock ();
198191 }
199192
200- inline void EndTurn (ExclusiveTurn & turn)
193+ inline void EndTurn (QueueEntry & turn)
201194 {// seqMutex_
202195 SeqMutexT::scoped_lock lock (seqMutex_);
203196
@@ -211,7 +204,64 @@ class ExclusiveTurnManager
211204 using SeqMutexT = tbb::queuing_mutex;
212205
213206 SeqMutexT seqMutex_;
214- ExclusiveTurn* tail_ = nullptr ;
207+ QueueEntry* tail_ = nullptr ;
208+ };
209+
210+ // //////////////////////////////////////////////////////////////////////////////////////
211+ // / DefaultQueueableTurn
212+ // //////////////////////////////////////////////////////////////////////////////////////
213+ template
214+ <
215+ typename TTurnBase
216+ >
217+ class DefaultQueueableTurn :
218+ public TTurnBase,
219+ public TurnQueueManager::QueueEntry
220+ {
221+ public:
222+ DefaultQueueableTurn (TurnIdT id, TurnFlagsT flags) :
223+ TTurnBase (id, flags),
224+ TurnQueueManager::QueueEntry (flags)
225+ {
226+ }
227+ };
228+
229+ // //////////////////////////////////////////////////////////////////////////////////////
230+ // / DefaultQueuingEngine
231+ // //////////////////////////////////////////////////////////////////////////////////////
232+ template
233+ <
234+ template <typename Turn_> class TTEngineBase ,
235+ typename TTurnBase
236+ >
237+ class DefaultQueuingEngine : public TTEngineBase <DefaultQueueableTurn<TTurnBase>>
238+ {
239+ public:
240+ using TurnT = DefaultQueueableTurn<TTurnBase>;
241+
242+ void OnTurnAdmissionStart (TurnT& turn)
243+ {
244+ queueManager_.StartTurn (turn);
245+ }
246+
247+ void OnTurnAdmissionEnd (TurnT& turn)
248+ {
249+ turn.RunMergedInputs ();
250+ }
251+
252+ void OnTurnEnd (TurnT& turn)
253+ {
254+ queueManager_.EndTurn (turn);
255+ }
256+
257+ template <typename F>
258+ bool TryMerge (F&& f)
259+ {
260+ return queueManager_.TryMerge (std::forward<F>(f));
261+ }
262+
263+ private:
264+ TurnQueueManager queueManager_;
215265};
216266
217267REACT_IMPL_END
0 commit comments