@@ -106,7 +106,7 @@ module Streamly.SVar
108import Control.Concurrent
108import Control.Concurrent
109− (ThreadId, myThreadId, threadDelay, getNumCapabilities, throwTo)
109+ (ThreadId, myThreadId, threadDelay, throwTo)
110import Control.Concurrent.MVar
110import Control.Concurrent.MVar
111 (MVar, newEmptyMVar, tryPutMVar, takeMVar, newMVar)
111 (MVar, newEmptyMVar, tryPutMVar, takeMVar, newMVar)
112import Control.Exception (SomeException(..), catch, mask, assert, Exception)
112import Control.Exception (SomeException(..), catch, mask, assert, Exception)
@@ -342,7 +342,6 @@ data SVar t m a = SVar
342 , outputDoorBell :: MVar () -- signal the consumer about output
342 , outputDoorBell :: MVar () -- signal the consumer about output
343 , readOutputQ :: m [ChildEvent a]
343 , readOutputQ :: m [ChildEvent a]
344 , postProcess :: m Bool
344 , postProcess :: m Bool
345− , hasDelayedOutput :: IO Bool
347 -- Combined/aggregate parameters
346 -- Combined/aggregate parameters
348 , maxWorkerLimit :: Limit
347 , maxWorkerLimit :: Limit
@@ -1171,20 +1170,6 @@ dequeueFromHeap hpVar =
1171 ((hp', Nothing), Ready ent)
1170 ((hp', Nothing), Ready ent)
1172 _ -> (pair, Waiting n)
1171 _ -> (pair, Waiting n)
1174−{-# INLINE canDequeueFromHeap #-}
1176− :: IORef (Heap (Entry Int (AheadHeapEntry t m a)), Maybe Int)
1178−canDequeueFromHeap hpVar =
1179− withIORef hpVar $ \(hp, snum) ->
1181− Nothing -> return True
1183− let r = H.uncons hp
1185− Just ((Entry seqNo _ev), _) -> return $ seqNo == n
1188{-# INLINE dequeueFromHeapSeq #-}
1173{-# INLINE dequeueFromHeapSeq #-}
1189dequeueFromHeapSeq
1174dequeueFromHeapSeq
1190 :: IORef (Heap (Entry Int (AheadHeapEntry t m a)), Maybe Int)
1175 :: IORef (Heap (Entry Int (AheadHeapEntry t m a)), Maybe Int)
@@ -1743,7 +1728,7 @@ sendWorkerDelayPaced :: SVar t m a -> IO ()
1743sendWorkerDelayPaced _ = return ()
1728sendWorkerDelayPaced _ = return ()
1745sendWorkerDelay :: SVar t m a -> IO ()
1730sendWorkerDelay :: SVar t m a -> IO ()
1746−sendWorkerDelay sv = do
1731+sendWorkerDelay _sv = do
1747 -- XXX we need a better way to handle this than hardcoded delays. The
1732 -- XXX we need a better way to handle this than hardcoded delays. The
1748 -- delays may be different for different systems.
1733 -- delays may be different for different systems.
1749 -- If there is a usecase where this is required we can create a combinator
1734 -- If there is a usecase where this is required we can create a combinator
@@ -1776,8 +1761,7 @@ sendWorkerWait delay dispatch sv = do
1777 liftIO $ delay sv
1762 liftIO $ delay sv
1778 (_, n) <- liftIO $ readIORef (outputQueue sv)
1763 (_, n) <- liftIO $ readIORef (outputQueue sv)
1779− hasOutput <- if (n > 0) then return True else liftIO $ hasDelayedOutput sv
1764+ when (n <= 0) $ do
1780− when (not hasOutput) $ do
1781 -- The queue may be empty temporarily if the worker has dequeued the
1765 -- The queue may be empty temporarily if the worker has dequeued the
1782 -- work item but has not enqueued the remaining part yet. For the same
1766 -- work item but has not enqueued the remaining part yet. For the same
1783 -- reason, a worker may come back if it tries to dequeue and finds the
1767 -- reason, a worker may come back if it tries to dequeue and finds the
@@ -2024,7 +2008,6 @@ getAheadSVar st f = do
2024 , outputDoorBell = outQMv
2008 , outputDoorBell = outQMv
2025 , readOutputQ = readOutput sv
2009 , readOutputQ = readOutput sv
2026 , postProcess = postProc sv
2010 , postProcess = postProc sv
2027− , hasDelayedOutput = canDequeueFromHeap outH
2028 , workerThreads = running
2011 , workerThreads = running
2029 , workLoop = f q outH st{streamVar = Just sv} sv
2012 , workLoop = f q outH st{streamVar = Just sv} sv
2030 , enqueue = enqueueAhead sv q
2013 , enqueue = enqueueAhead sv q
@@ -2122,7 +2105,6 @@ getParallelSVar st = do
2122 , outputDoorBell = outQMv
2105 , outputDoorBell = outQMv
2123 , readOutputQ = readOutputQPar sv
2106 , readOutputQ = readOutputQPar sv
2124 , postProcess = allThreadsDone sv
2107 , postProcess = allThreadsDone sv
2125− , hasDelayedOutput = return False
2126 , workerThreads = running
2108 , workerThreads = running
2127 , workLoop = undefined
2109 , workLoop = undefined
2128 , enqueue = undefined
2110 , enqueue = undefined