Skip to content

Commit 8107a77

Browse files
committed
removed dependency from atomic-primops, better console IO, added 'rerun' to Logged.hs
1 parent ef20d52 commit 8107a77

File tree

10 files changed

+527
-108
lines changed

10 files changed

+527
-108
lines changed

0

Whitespace-only changes.

src/Transient/Base.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,7 @@ TransIO, TransientIO
250250

251251
-- * State management
252252
,setData, getSData, getData, delData, modifyData, modifyData', try, setState, getState, delState, getRState,setRState, modifyState
253+
,labelState, findState, killState
253254

254255
-- * Thread management
255256
, threads,addThreads, freeThreads, hookedThreads,oneThread, killChilds
@@ -260,7 +261,7 @@ TransIO, TransientIO
260261
,onException, onException', cutExceptions, continue, catcht, throwt
261262

262263
-- * Utilities
263-
,genId
264+
,genId, Loggable
264265
)
265266

266267
where

src/Transient/Indeterminism.hs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,22 @@
1313
-----------------------------------------------------------------------------
1414
{-# LANGUAGE ScopedTypeVariables, CPP #-}
1515
module Transient.Indeterminism (
16-
choose, choose', chooseStream, collect, collect', group, groupByTime
16+
choose, choose', chooseStream, collect, collect', group, groupByTime, burst
1717
) where
1818

1919
import Transient.Internals hiding (retry)
2020

2121
import Data.IORef
2222
import Control.Applicative
2323
import Data.Monoid
24-
import Control.Concurrent
24+
import Control.Concurrent
2525
import Data.Typeable
2626
import Control.Monad.State
2727
import GHC.Conc
2828
import Data.Time.Clock
2929
import Control.Exception
3030

31-
#ifndef ETA_VERSION
32-
import Data.Atomics
33-
#endif
31+
3432

3533

3634
-- | Converts a list of pure values into a transient task set. You can use the
@@ -46,7 +44,7 @@ chooseStream []= empty
4644
chooseStream xs = do
4745
evs <- liftIO $ newIORef xs
4846
parallel $ do
49-
es <- atomicModifyIORefCAS evs $ \es -> let tes= tail es in (tes,es)
47+
es <- atomicModifyIORef evs $ \es -> let tes= tail es in (tes,es)
5048
case es of
5149
[x] -> x `seq` return $ SLast x
5250
x:_ -> x `seq` return $ SMore x
@@ -65,7 +63,7 @@ group num proc = do
6563
v <- liftIO $ newIORef (0,[])
6664
x <- proc
6765

68-
mn <- liftIO $ atomicModifyIORefCAS v $ \(n,xs) ->
66+
mn <- liftIO $ atomicModifyIORef v $ \(n,xs) ->
6967
let n'=n +1
7068
in if n'== num
7169

@@ -87,7 +85,7 @@ groupByTime1 time proc = do
8785
8886
x <- proc
8987
t' <- liftIO getCurrentTime
90-
mn <- liftIO $ atomicModifyIORefCAS v $ \(n,t,xs) -> let n'=n +1
88+
mn <- liftIO $ atomicModifyIORef v $ \(n,t,xs) -> let n'=n +1
9189
in
9290
if diffUTCTime t' t < fromIntegral time
9391
then ((n',t, x:xs),Nothing)
@@ -112,7 +110,7 @@ collect n = collect' n 0
112110
--
113111
collect' :: Int -> Int -> TransIO a -> TransIO [a]
114112
collect' n t search= do
115-
addThreads 1
113+
116114

117115
rv <- liftIO $ newEmptyMVar -- !> "NEWMVAR"
118116

@@ -124,7 +122,9 @@ collect' n t search= do
124122
stop
125123

126124
timer= do
127-
when (t > 0) . async $ threadDelay t >> putMVar rv Nothing
125+
when (t > 0) $ do
126+
addThreads 1
127+
async $ threadDelay t >> putMVar rv Nothing
128128
empty
129129

130130
monitor= liftIO loop
@@ -137,7 +137,7 @@ collect' n t search= do
137137
case mr of
138138
Nothing -> return rs
139139
Just r -> do
140-
let n''= n' +1
140+
let n''= n' + 1
141141
let rs'= r:rs
142142
writeIORef results (n'',rs')
143143

@@ -149,10 +149,10 @@ collect' n t search= do
149149
readIORef results >>= return . snd
150150

151151

152-
oneThread $ timer <|> worker <|> monitor
152+
oneThread $ timer <|> worker <|> monitor
153153

154154

155-
-- | insert `SDone` response everytime there is a timeout since the last response
155+
-- | insert `SDone` response every time there is a timeout since the last response
156156

157157
burst :: Int -> TransIO a -> TransIO (StreamData a)
158158
burst timeout comp= do
@@ -166,12 +166,12 @@ groupByTime timeout comp= do
166166
where
167167
run v = do
168168
x <- comp
169-
liftIO $ atomicModifyIORefCAS v $ \xs -> (xs <> x,())
169+
liftIO $ atomicModifyIORef v $ \xs -> (xs <> x,())
170170
empty
171171

172172
gather v= waitEvents $ do
173173
threadDelay timeout
174-
atomicModifyIORefCAS v $ \xs -> (mempty , xs)
174+
atomicModifyIORef v $ \xs -> (mempty , xs)
175175

176176

177177

0 commit comments

Comments
 (0)