summaryrefslogtreecommitdiff
path: root/Types/TransferrerPool.hs
diff options
context:
space:
mode:
authorJoey Hess <joeyh@joeyh.name>2020-12-07 13:08:59 -0400
committerJoey Hess <joeyh@joeyh.name>2020-12-07 13:21:35 -0400
commit47016fc6569fe5f27067f60302b42ef7cbc13371 (patch)
tree38bb155790ac1742b96621f41f5bd6c3838d479b /Types/TransferrerPool.hs
parent72e5764a87a088e21e12bb51c52650ca965d2596 (diff)
move TransferrerPool from Assistant state to Annex state
This commit was sponsored by Graham Spencer on Patreon.
Diffstat (limited to 'Types/TransferrerPool.hs')
-rw-r--r--Types/TransferrerPool.hs21
1 files changed, 10 insertions, 11 deletions
diff --git a/Types/TransferrerPool.hs b/Types/TransferrerPool.hs
index e6019f27f0..72d61a3b9a 100644
--- a/Types/TransferrerPool.hs
+++ b/Types/TransferrerPool.hs
@@ -7,11 +7,11 @@
module Types.TransferrerPool where
-import Annex.Common
+import Common
import Control.Concurrent.STM hiding (check)
-type TransferrerPool = TVar (MkCheckTransferrer, [TransferrerPoolItem])
+type TransferrerPool = TVar [TransferrerPoolItem]
type CheckTransferrer = IO Bool
type MkCheckTransferrer = IO (IO Bool)
@@ -27,30 +27,29 @@ data Transferrer = Transferrer
, transferrerHandle :: ProcessHandle
}
-newTransferrerPool :: MkCheckTransferrer -> IO TransferrerPool
-newTransferrerPool c = newTVarIO (c, [])
+newTransferrerPool :: IO TransferrerPool
+newTransferrerPool = newTVarIO []
popTransferrerPool :: TransferrerPool -> STM (Maybe TransferrerPoolItem, Int)
popTransferrerPool p = do
- (c, l) <- readTVar p
+ l <- readTVar p
case l of
[] -> return (Nothing, 0)
(i:is) -> do
- writeTVar p (c, is)
+ writeTVar p is
return $ (Just i, length is)
pushTransferrerPool :: TransferrerPool -> TransferrerPoolItem -> STM ()
pushTransferrerPool p i = do
- (c, l) <- readTVar p
+ l <- readTVar p
let l' = i:l
- writeTVar p (c, l')
+ writeTVar p l'
{- Note that making a CheckTransferrer may allocate resources,
- such as a NotificationHandle, so it's important that the returned
- TransferrerPoolItem is pushed into the pool, and not left to be
- garbage collected. -}
-mkTransferrerPoolItem :: TransferrerPool -> Transferrer -> IO TransferrerPoolItem
-mkTransferrerPoolItem p t = do
- mkcheck <- atomically $ fst <$> readTVar p
+mkTransferrerPoolItem :: MkCheckTransferrer -> Transferrer -> IO TransferrerPoolItem
+mkTransferrerPoolItem mkcheck t = do
check <- mkcheck
return $ TransferrerPoolItem (Just t) check