@@ -185,22 +185,24 @@ class TurnQueueManager
185185 inline void UnblockSuccessors ()
186186 {
187187 for (const auto & e : merged_)
188- e.second ->Unblock ();
188+ if (e.second != nullptr )
189+ e.second ->Unblock ();
189190
190191 if (successor_)
191192 successor_->blockCondition_ .Unblock ();
192193 }
193194
194195 template <typename F>
195- inline bool TryMerge (F&& inputFunc, BlockingCondition& caller)
196+ inline bool TryMerge (F&& inputFunc, BlockingCondition* caller)
196197 {
197198 if (!isMergeable_)
198199 return false ;
199200
200201 // Only merge if target is still blocked
201202 bool merged = blockCondition_.RunIfBlocked ([&] {
202- caller.Block ();
203- merged_.emplace_back (std::make_pair (std::forward<F>(inputFunc), &caller));
203+ if (caller)
204+ caller->Block ();
205+ merged_.emplace_back (std::make_pair (std::forward<F>(inputFunc), caller));
204206 });
205207
206208 return merged;
@@ -230,7 +232,7 @@ class TurnQueueManager
230232 SeqMutexT::scoped_lock lock (seqMutex_);
231233
232234 if (tail_)
233- merged = tail_->TryMerge (std::forward<F>(inputFunc), caller);
235+ merged = tail_->TryMerge (std::forward<F>(inputFunc), & caller);
234236 }// ~seqMutex_
235237
236238 if (merged)
@@ -239,7 +241,22 @@ class TurnQueueManager
239241 return merged;
240242 }
241243
242- inline void StartTurn (QueueEntry& turn)
244+ template <typename F>
245+ inline bool TryMergeAsync (F&& inputFunc)
246+ {
247+ bool merged = false ;
248+
249+ {// seqMutex_
250+ SeqMutexT::scoped_lock lock (seqMutex_);
251+
252+ if (tail_)
253+ merged = tail_->TryMerge (std::forward<F>(inputFunc), nullptr );
254+ }// ~seqMutex_
255+
256+ return merged;
257+ }
258+
259+ inline void EnterQueue (QueueEntry& turn)
243260 {
244261 {// seqMutex_
245262 SeqMutexT::scoped_lock lock (seqMutex_);
@@ -253,7 +270,7 @@ class TurnQueueManager
253270 turn.WaitForUnblock ();
254271 }
255272
256- inline void EndTurn (QueueEntry& turn)
273+ inline void ExitQueue (QueueEntry& turn)
257274 {// seqMutex_
258275 SeqMutexT::scoped_lock lock (seqMutex_);
259276
@@ -273,10 +290,7 @@ class TurnQueueManager
273290// /////////////////////////////////////////////////////////////////////////////////////////////////
274291// / DefaultQueueableTurn
275292// /////////////////////////////////////////////////////////////////////////////////////////////////
276- template
277- <
278- typename TTurnBase
279- >
293+ template <typename TTurnBase>
280294class DefaultQueueableTurn :
281295 public TTurnBase,
282296 public TurnQueueManager::QueueEntry
@@ -301,29 +315,32 @@ class DefaultQueuingEngine : public TTEngineBase<DefaultQueueableTurn<TTurnBase>
301315public:
302316 using TurnT = DefaultQueueableTurn<TTurnBase>;
303317
304- void OnTurnAdmissionStart (TurnT& turn)
318+ template <typename F>
319+ bool TryMergeInput (F&& f, bool isBlocking)
305320 {
306- queueManager_.StartTurn (turn);
321+ if (isBlocking)
322+ return queueManager_.TryMerge (std::forward<F>(f));
323+ else
324+ return queueManager_.TryMergeAsync (std::forward<F>(f));
307325 }
308326
309- void OnTurnAdmissionEnd (TurnT& turn)
327+ void ApplyMergedInputs (TurnT& turn)
310328 {
311329 turn.RunMergedInputs ();
312330 }
313331
314- void OnTurnEnd (TurnT& turn)
332+ void EnterTurnQueue (TurnT& turn)
315333 {
316- queueManager_.EndTurn (turn);
334+ queueManager_.EnterQueue (turn);
317335 }
318-
319- template <typename F>
320- bool TryMerge (F&& f)
336+
337+ void ExitTurnQueue (TurnT& turn)
321338 {
322- return queueManager_.TryMerge (std::forward<F>(f) );
339+ queueManager_.ExitQueue (turn );
323340 }
324341
325342private:
326- TurnQueueManager queueManager_;
343+ TurnQueueManager queueManager_;
327344};
328345
329346/* ***************************************/ REACT_IMPL_END /* **************************************/
0 commit comments