@@ -84,7 +84,7 @@ workLoopLIFO qref sv winfo = run
8484 run = do
8585 work <- dequeue qref
8686 case work of
87- Nothing -> liftIO $ stopWith winfo sv
87+ Nothing -> return ()
8888 Just (RunInIO runin, m) -> process runin m
8989
9090 process runin m = do
@@ -105,7 +105,7 @@ workLoopLIFO qref sv winfo = run
105105 res <- restoreM r
106106 case res of
107107 Continue -> run
108- Suspend -> liftIO $ stopWith winfo sv
108+ Suspend -> return ()
109109
110110 where
111111
@@ -143,8 +143,9 @@ workLoopLIFOLimited qref sv winfo = run
143143
144144 run = do
145145 work <- dequeue qref
146+ {- HLINT ignore "Use forM_" -}
146147 case work of
147- Nothing -> liftIO $ stopWith winfo sv
148+ Nothing -> return ()
148149 Just item -> process item
149150
150151 process item@ (RunInIO runin, m) = do
@@ -167,13 +168,12 @@ workLoopLIFOLimited qref sv winfo = run
167168 res <- restoreM r
168169 case res of
169170 Continue -> run
170- Suspend -> liftIO $ stopWith winfo sv
171+ Suspend -> return ()
171172 -- Avoid any side effects, undo the yield limit decrement if we
172173 -- never yielded anything.
173174 else liftIO $ do
174175 enqueueLIFO sv qref item
175176 incrementYieldLimit (remainingWork sv)
176- stopWith winfo sv
177177
178178 where
179179
@@ -497,11 +497,6 @@ preStopCheck sv heap =
497497 if beyondRate then stopping else continue
498498 else stopping
499499
500- abortExecution :: Channel m a -> Maybe WorkerInfo -> IO ()
501- abortExecution sv winfo = do
502- incrementYieldLimit (remainingWork sv)
503- stopWith winfo sv
504-
505500-- XXX In absence of a "noyield" primitive (i.e. do not pre-empt inside a
506501-- critical section) from GHC RTS, we have a difficult problem. Assume we have
507502-- a 100,000 threads producing output and queuing it to the heap for
@@ -580,32 +575,31 @@ processHeap q heap sv winfo entry sno stopping = loopHeap sno entry
580575 liftIO $ do
581576 requeueOnHeapTop heap ent seqNo
582577 incrementYieldLimit (remainingWork sv)
583- stopWith winfo sv
584578
585579 processWorkQueue prevSeqNo = do
586580 yieldLimitOk <- liftIO $ decrementYieldLimit (remainingWork sv)
587581 if yieldLimitOk
588582 then do
589583 work <- dequeueAhead q
590584 case work of
591- Nothing -> liftIO $ stopWith winfo sv
585+ Nothing -> return ()
592586 Just (m, seqNo) -> do
593587 if seqNo == prevSeqNo + 1
594588 then processWithToken q heap sv winfo m seqNo
595589 else processWithoutToken q heap sv winfo m seqNo
596- else liftIO $ abortExecution sv winfo
590+ else liftIO $ incrementYieldLimit (remainingWork sv)
597591
598592 nextHeap prevSeqNo = do
599593 res <- liftIO $ dequeueFromHeapSeq heap (prevSeqNo + 1 )
600594 case res of
601595 Ready (Entry seqNo hent) -> loopHeap seqNo hent
602- Clearing -> liftIO $ stopWith winfo sv
596+ Clearing -> return ()
603597 Waiting _ ->
604598 if stopping
605599 then do
606600 r <- liftIO $ preStopCheck sv heap
607601 if r
608- then liftIO $ stopWith winfo sv
602+ then return ()
609603 else processWorkQueue prevSeqNo
610604 else inline processWorkQueue prevSeqNo
611605
@@ -643,7 +637,6 @@ processHeap q heap sv winfo entry sno stopping = loopHeap sno entry
643637 then liftIO $ do
644638 -- put the entry back in the heap and stop
645639 requeueOnHeapTop heap (Entry seqNo ent) seqNo
646- stopWith winfo sv
647640 else go
648641 else go
649642 AheadEntryStream (RunInIO runin, Nothing , r) -> do
@@ -660,7 +653,6 @@ processHeap q heap sv winfo entry sno stopping = loopHeap sno entry
660653 then liftIO $ do
661654 -- put the entry back in the heap and stop
662655 requeueOnHeapTop heap (Entry seqNo ent) seqNo
663- stopWith winfo sv
664656 else go
665657 else go
666658
@@ -677,7 +669,7 @@ drainHeap q heap sv winfo = do
677669 case r of
678670 Ready (Entry seqNo hent) ->
679671 processHeap q heap sv winfo hent seqNo True
680- _ -> liftIO $ stopWith winfo sv
672+ _ -> return ()
681673
682674data HeapStatus = HContinue | HStop
683675
@@ -902,7 +894,7 @@ workLoopAhead q heap sv winfo = do
902894 case r of
903895 Ready (Entry seqNo hent) ->
904896 processHeap q heap sv winfo hent seqNo False
905- Clearing -> liftIO $ stopWith winfo sv
897+ Clearing -> return ()
906898 Waiting _ -> do
907899 -- Before we execute the next item from the work queue we check
908900 -- if we are beyond the yield limit. It is better to check the
@@ -925,12 +917,12 @@ workLoopAhead q heap sv winfo = do
925917 then do
926918 work <- dequeueAhead q
927919 case work of
928- Nothing -> liftIO $ stopWith winfo sv
920+ Nothing -> return ()
929921 Just (m, seqNo) -> do
930922 if seqNo == 0
931923 then processWithToken q heap sv winfo m seqNo
932924 else processWithoutToken q heap sv winfo m seqNo
933- else liftIO $ abortExecution sv winfo
925+ else liftIO $ incrementYieldLimit (remainingWork sv)
934926
935927-------------------------------------------------------------------------------
936928-- SVar creation
@@ -967,6 +959,7 @@ getLifoSVar mrun cfg = do
967959 case getYieldLimit cfg of
968960 Nothing -> return Nothing
969961 Just x -> Just <$> newIORef x
962+ stopRef <- newIORef False
970963 rateInfo <- newRateInfo cfg
971964
972965 stats <- newSVarStats
@@ -1015,6 +1008,7 @@ getLifoSVar mrun cfg = do
10151008 if inOrder
10161009 then workLoopAhead aheadQ outH sv
10171010 else wloop q sv
1011+ , channelStopped = stopRef
10181012 , enqueue =
10191013 if inOrder
10201014 then enqueueAhead sv aheadQ
0 commit comments