@@ -45,6 +45,8 @@ module Streamly.SVar
45 , getYieldLimit
45 , getYieldLimit
46 , setYieldLimit
46 , setYieldLimit
48 -- SVar related
50 -- SVar related
49 , newAheadVar
51 , newAheadVar
50 , newParallelVar
52 , newParallelVar
@@ -95,7 +97,7 @@ module Streamly.SVar
97import Control.Concurrent
99import Control.Concurrent
98− (ThreadId, myThreadId, threadDelay, getNumCapabilities)
100+ (ThreadId, myThreadId, threadDelay, getNumCapabilities, throwTo)
99import Control.Concurrent.MVar
101import Control.Concurrent.MVar
100 (MVar, newEmptyMVar, tryPutMVar, takeMVar, newMVar)
102 (MVar, newEmptyMVar, tryPutMVar, takeMVar, newMVar)
101import Control.Exception (SomeException(..), catch, mask, assert, Exception)
103import Control.Exception (SomeException(..), catch, mask, assert, Exception)
@@ -318,9 +320,9 @@ data SVar t m a = SVar
318 , workerStopMVar :: MVar ()
320 , workerStopMVar :: MVar ()
320 , svarStats :: SVarStats
322 , svarStats :: SVarStats
322 -- to track garbage collection of SVar
323 -- to track garbage collection of SVar
323 , svarRef :: Maybe (IORef ())
324 , svarRef :: Maybe (IORef ())
324 , outputHeap :: IORef (Heap (Entry Int (AheadHeapEntry t m a)) , Int)
326 , outputHeap :: IORef (Heap (Entry Int (AheadHeapEntry t m a)) , Int)
325 -- Shared work queue (stream, seqNo)
327 -- Shared work queue (stream, seqNo)
326 , aheadWorkQueue :: IORef ([t m a], Int)
328 , aheadWorkQueue :: IORef ([t m a], Int)
@@ -460,6 +462,16 @@ setStreamLatency n st =
460getStreamLatency :: State t m a -> Maybe NanoSecs
462getStreamLatency :: State t m a -> Maybe NanoSecs
461getStreamLatency = _streamLatency
463getStreamLatency = _streamLatency
465+-------------------------------------------------------------------------------
467+-------------------------------------------------------------------------------
469+cleanupSVar :: SVar t m a -> IO ()
471+ workers <- readIORef (workerThreads sv)
472+ Prelude.mapM_ (\tid -> throwTo tid ThreadAbort)
463-------------------------------------------------------------------------------
475-------------------------------------------------------------------------------
464-- Dumping the SVar for debug/diag
476-- Dumping the SVar for debug/diag
465-------------------------------------------------------------------------------
477-------------------------------------------------------------------------------
@@ -1648,8 +1660,8 @@ getAheadSVar st f = do
1648 , workerCount = active
1660 , workerCount = active
1649 , accountThread = delThread sv
1661 , accountThread = delThread sv
1650 , workerStopMVar = stopMVar
1662 , workerStopMVar = stopMVar
1652 , svarRef = Nothing
1663 , svarRef = Nothing
1653 , aheadWorkQueue = q
1665 , aheadWorkQueue = q
1654 , outputHeap = outH
1666 , outputHeap = outH
@@ -1733,8 +1745,8 @@ getParallelSVar st = do
1733 , workerCount = active
1745 , workerCount = active
1734 , accountThread = modifyThread sv
1746 , accountThread = modifyThread sv
1735 , workerStopMVar = undefined
1747 , workerStopMVar = undefined
1737 , svarRef = Nothing
1748 , svarRef = Nothing
1738 , aheadWorkQueue = undefined
1750 , aheadWorkQueue = undefined
1739 , outputHeap = undefined
1751 , outputHeap = undefined