on master help sign in
rename threads to maxThreads and buffer to maxBuffer
commit72766cb82bb98ab30fce7d74b3f962521d4543d8 authorHarendra Kumar <harendra.kumar@gmail.com> dateSun 1 Jul 2018, 23:53 (8 years ago) parent211df79
6 files changed+36−34
src/Streamly.hs+15−3 src/Streamly/SVar.hs+5−5 src/Streamly/Streams/Ahead.hs+1−1 src/Streamly/Streams/Async.hs+4−4 src/Streamly/Streams/SVar.hs+10−20 test/Prop.hs+1−1
src/Streamly.hs+15−3
@@ -101,8 +101,9 @@ module Streamly
101101 , parallel
102102
103103 -- * Concurrency Control
104− , threads
105− , buffer
104+ -- $concurrency
105+ , maxThreads
106+ , maxBuffer
106107
107108 -- * Folding Containers of Streams
108109 -- $foldutils
@@ -163,7 +164,7 @@ import Streamly.Streams.Ahead
163164import Streamly.Streams.Parallel
164165import Streamly.Streams.Zip
165166import Streamly.Streams.Prelude
166−import Streamly.Streams.SVar (threads, buffer)
167+import Streamly.Streams.SVar (maxThreads, maxBuffer)
167168import Streamly.SVar (MonadAsync)
168169import Data.Semigroup (Semigroup(..))
169170
@@ -214,6 +215,17 @@ import Data.Semigroup (Semigroup(..))
214215-- which can be used to combine two streams in a predetermined way irrespective
215216-- of the type.
216217
218+-- $concurrency
219+--
220+-- These combinators can be used at any point in the composition to control
221+-- concurrency, and they affect only the enclosed stream. When nested
222+-- combinators are used, the nearest enclosing combinator overrides the outer
223+-- ones. These combinators have no effect on 'Parallel' streams, concurrency
224+-- for 'Parallel' streams is always unbounded.
225+-- Note that the use of these combinators does not enable concurrency, to
226+-- enable concurrency you have to use one of the concurrent stream type
227+-- combinators.
228+
217229-- $adapters
218230--
219231-- You may want to use different stream composition styles at different points
src/Streamly/SVar.hs+5−5
@@ -188,8 +188,8 @@ data SVar t m a =
188188
189189data State t m a = State
190190 { streamVar :: Maybe (SVar t m a)
191− , maxThreads :: Int
192− , maxBuffer :: Int
191+ , threadsHigh :: Int
192+ , bufferHigh :: Int
193193 }
194194
195195defaultMaxThreads, defaultMaxBuffer :: Int
@@ -199,8 +199,8 @@ defaultMaxBuffer = 1500
199199defState :: State t m a
200200defState = State
201201 { streamVar = Nothing
202− , maxThreads = defaultMaxThreads
203− , maxBuffer = defaultMaxBuffer
202+ , threadsHigh = defaultMaxThreads
203+ , bufferHigh = defaultMaxBuffer
204204 }
205205
206206-- We can optimize this so that we clear it only if it is a Just value, it
@@ -827,7 +827,7 @@ getAheadSVar st f = do
827827 let sv =
828828 SVar { outputQueue = outQ
829829 , outputDoorBell = outQMv
830− , readOutputQ = readOutputQBounded (maxThreads st) sv
830+ , readOutputQ = readOutputQBounded (threadsHigh st) sv
831831 , postProcess = postProcessBounded sv
832832 , workerThreads = running
833833 -- , workLoop = workLoopAhead sv q outH
src/Streamly/Streams/Ahead.hs+1−1
@@ -124,7 +124,7 @@ workLoopAhead st q heap = runHeap
124124 where
125125
126126 sv = fromJust $ streamVar st
127− maxBuf = maxBuffer st
127+ maxBuf = bufferHigh st
128128 toHeap seqNo ent = do
129129 hp <- liftIO $ atomicModifyIORefCAS heap $ \(h, snum) ->
130130 ((H.insert (Entry seqNo ent) h, snum), h)
src/Streamly/Streams/Async.hs+4−4
@@ -70,7 +70,7 @@ runStreamLIFO :: MonadIO m
7070runStreamLIFO st q m stop = unStream m st stop single yieldk
7171 where
7272 sv = fromJust $ streamVar st
73− maxBuf = maxBuffer st
73+ maxBuf = bufferHigh st
7474 single a = do
7575 res <- liftIO $ send maxBuf sv (ChildYield a)
7676 if res then stop else liftIO $ sendStop sv
@@ -95,7 +95,7 @@ runStreamFIFO
9595runStreamFIFO st q m stop = unStream m st stop single yieldk
9696 where
9797 sv = fromJust $ streamVar st
98− maxBuf = maxBuffer st
98+ maxBuf = bufferHigh st
9999 single a = do
100100 res <- liftIO $ send maxBuf sv (ChildYield a)
101101 if res then stop else liftIO $ sendStop sv
@@ -132,7 +132,7 @@ getLifoSVar st = do
132132 let sv =
133133 SVar { outputQueue = outQ
134134 , outputDoorBell = outQMv
135− , readOutputQ = readOutputQBounded (maxThreads st) sv
135+ , readOutputQ = readOutputQBounded (threadsHigh st) sv
136136 , postProcess = postProcessBounded sv
137137 , workerThreads = running
138138 , workLoop = workLoopLIFO runStreamLIFO
@@ -173,7 +173,7 @@ getFifoSVar st = do
173173 let sv =
174174 SVar { outputQueue = outQ
175175 , outputDoorBell = outQMv
176− , readOutputQ = readOutputQBounded (maxThreads st) sv
176+ , readOutputQ = readOutputQBounded (threadsHigh st) sv
177177 , postProcess = postProcessBounded sv
178178 , workerThreads = running
179179 , workLoop = workLoopFIFO runStreamFIFO
src/Streamly/Streams/SVar.hs+10−20
@@ -23,8 +23,8 @@ module Streamly.Streams.SVar
2323 (
2424 fromSVar
2525 , toSVar
26− , threads
27− , buffer
26+ , maxThreads
27+ , maxBuffer
2828 )
2929where
3030
@@ -89,32 +89,22 @@ toSVar sv m = toStreamVar sv (toStream m)
8989-- when using concurrent streams. This is not the grand total number of threads
9090-- but maximum threads at each point of concurrency.
9191-- A value of 0 resets the thread limit to default, a negative value means
92−-- there is no limit. Note that this primitive has no effect on 'Parallel'
93−-- streams, the number of threads for 'Parallel' streams are always unbounded.
94−--
95−-- This primitive can be used at any point in the composition, and it affects
96−-- only the enclosed stream. When nested primitives are used the nearest
97−-- enclosing primitive overrides the outer ones.
98−-- Note that the use of this primitive does not enable concurrency, to enable
99−-- concurrency you have to use one of the concurrent stream type combinators.
92+-- there is no limit.
10093--
10194-- @since 0.4.0
102−threads :: IsStream t => Int -> t m a -> t m a
103−threads n m = fromStream $ Stream $ \st stp sng yld -> do
95+maxThreads :: IsStream t => Int -> t m a -> t m a
96+maxThreads n m = fromStream $ Stream $ \st stp sng yld -> do
10497 let n' = if n == 0 then defaultMaxThreads else n
105− unStream (toStream m) (st {maxThreads = n'}) stp sng yld
98+ unStream (toStream m) (st {threadsHigh = n'}) stp sng yld
10699
107100-- | Specify the maximum size of the buffer for storing the results from
108101-- concurrent computations. If the buffer becomes full we stop spawning more
109102-- concurrent tasks until there is space in the buffer.
110103-- A value of 0 resets the buffer size to default, a negative value means
111−-- there is no limit. Note that this primitive has no effect on 'Parallel'
112−-- streams, the buffer size for 'Parallel' streams is always unbounded.
113−--
114−-- The same scoping rules apply as for the 'threads' primitive.
104+-- there is no limit.
115105--
116106-- @since 0.4.0
117−buffer :: IsStream t => Int -> t m a -> t m a
118−buffer n m = fromStream $ Stream $ \st stp sng yld -> do
107+maxBuffer :: IsStream t => Int -> t m a -> t m a
108+maxBuffer n m = fromStream $ Stream $ \st stp sng yld -> do
119109 let n' = if n == 0 then defaultMaxBuffer else n
120− unStream (toStream m) (st {maxBuffer = n'}) stp sng yld
110+ unStream (toStream m) (st {bufferHigh = n'}) stp sng yld
test/Prop.hs+1−1
@@ -56,7 +56,7 @@ constructWithReplicateM
5656constructWithReplicateM op thr buf len =
5757 monadicIO $ do
5858 let x = return (1 :: Int)
59− stream <- run $ (S.toList . op) (threads thr $ buffer buf $
59+ stream <- run $ (S.toList . op) (maxThreads thr $ maxBuffer buf $
6060 S.replicateM (fromIntegral len) x)
6161 list <- run $ replicateM (fromIntegral len) x
6262 equals (==) stream list