Skip to content

Commit

Permalink
Kill the use of 'modify'.
Browse files Browse the repository at this point in the history
  • Loading branch information
jlouis committed Jan 17, 2011
1 parent 57c81ea commit 1dc003c
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions src/Process/PieceMgr.hs
Expand Up @@ -155,7 +155,8 @@ traceMsg :: PieceMgrMsg -> Process CF ST ()
traceMsg m = {-# SCC "traceMsg" #-} do
tb <- gets traceBuffer
let !ntb = (trace $! show m) tb
modify (\db -> db { traceBuffer = ntb })
db <- get
put $! db { traceBuffer = ntb }

rpcMessage :: Process CF ST ()
rpcMessage = do
Expand Down Expand Up @@ -186,7 +187,8 @@ storeBlock pn blk d = {-# SCC "storeBlock" #-} do
writeFS
dld <- gets downloading
let !ndl = S.delete (pn, blk) dld
modify (\s -> s { downloading = ndl })
s <- get
put $! s { downloading = ndl }
endgameBroadcast pn blk
done <- updateProgress pn blk
when done (pieceDone pn)
Expand Down Expand Up @@ -218,7 +220,9 @@ peerHave idxs tmv = {-# SCC "peerHave" #-} do
liftIO . atomically $ putTMVar tmv interesting
if null interesting
then return ()
else modify (\db -> db { histogram = PendS.haves interesting (histogram db)})
else do
db <- get
put $! db { histogram = PendS.haves interesting (histogram db)}
where mem ps p =
case M.lookup p ps of
Nothing -> False
Expand Down Expand Up @@ -490,7 +494,9 @@ assertST = {-# SCC "assertST" #-} do
assertSets >> assertDownloading
sizes <- sizeReport
debugP sizes
else modify (\db -> db { assertCount = assertCount db - 1 })
else do
db <- get
put $! db { assertCount = assertCount db - 1 }
where
-- If a piece is pending in the database, we have the following rules:
--
Expand Down Expand Up @@ -524,11 +530,10 @@ assertST = {-# SCC "assertST" #-} do
-- - If a block is ipPending, it is not in the downloading list
-- - If a block is ipHave, it is not in the downloading list
assertDownloading = do
down <- S.toList <$> gets downloading
mapM_ checkDownloading down
checkDownloading (pn, blk) = do
pie <- gets pieces
tr <- gets traceBuffer
mapM_ (checkDownloading pie tr) =<< S.toList <$> gets downloading
checkDownloading pie tr (pn, blk) = do
case M.lookup pn pie of
Nothing -> fail $ "Piece " ++ show pn ++ " not in progress while We think it was"
Just Pending -> fail "Impossible (checkDownloading, Pending)"
Expand Down

0 comments on commit 1dc003c

Please sign in to comment.