diff options
author | Joey Hess <joey@kitenet.net> | 2013-04-25 01:33:44 -0400 |
---|---|---|
committer | Joey Hess <joey@kitenet.net> | 2013-04-25 01:33:44 -0400 |
commit | 6c8f6abbd5f1227fdbb7b8c93f257dca9b6a1372 (patch) | |
tree | 6ee22bd09c565135bbf5bde65efbaba640accae3 /Utility | |
parent | 2efb559c7cdce21fb441343c26af4855b6ac842f (diff) |
use DList for the transfer queue
Some nice efficiency gains here for list appending, although mostly
the small size of the transfer queue makes them irrelivant.
Diffstat (limited to 'Utility')
-rw-r--r-- | Utility/TList.hs | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/Utility/TList.hs b/Utility/TList.hs index 33a50b7dd..716f72017 100644 --- a/Utility/TList.hs +++ b/Utility/TList.hs @@ -25,10 +25,14 @@ newTList = newEmptyTMVar getTList :: TList a -> STM [a] getTList tlist = D.toList <$> takeTMVar tlist -{- Gets anything currently in the TList, without blocking. +{- Takes anything currently in the TList, without blocking. - TList is left empty. -} +takeTList :: TList a -> STM [a] +takeTList tlist = maybe [] D.toList <$> tryTakeTMVar tlist + +{- Reads anything in the list, without modifying it, or blocking. -} readTList :: TList a -> STM [a] -readTList tlist = maybe [] D.toList <$> tryTakeTMVar tlist +readTList tlist = maybe [] D.toList <$> tryReadTMVar tlist {- Mutates a TList. -} modifyTList :: TList a -> (D.DList a -> D.DList a) -> STM () @@ -50,3 +54,6 @@ snocTList tlist v = modifyTList tlist $ \dl -> D.snoc dl v appendTList :: TList a -> [a] -> STM () appendTList tlist l = modifyTList tlist $ \dl -> D.append dl (D.fromList l) + +setTList :: TList a -> [a] -> STM () +setTList tlist l = modifyTList tlist $ const $ D.fromList l |