stm-chans 2.0.0 → 2.1.0
raw patch · 12 files changed
+160/−63 lines, 12 filesdep ~stm
Dependency ranges changed: stm
Files
- VERSION +4/−0
- src/Control/Concurrent/STM/TBChan.hs +7/−4
- src/Control/Concurrent/STM/TBMChan.hs +8/−4
- src/Control/Concurrent/STM/TBMQueue.hs +10/−9
- src/Control/Concurrent/STM/TBQueue/Compat.hs +9/−10
- src/Control/Concurrent/STM/TChan/Compat.hs +66/−13
- src/Control/Concurrent/STM/TMChan.hs +28/−4
- src/Control/Concurrent/STM/TMQueue.hs +9/−6
- src/Control/Concurrent/STM/TMVar/Compat.hs +3/−2
- src/Control/Concurrent/STM/TQueue/Compat.hs +7/−5
- src/Control/Concurrent/STM/TVar/Compat.hs +4/−1
- stm-chans.cabal +5/−5
VERSION view
@@ -1,3 +1,7 @@+2.1.0 (2013-XX-XX):+ - Added UNPACK pragmas everywhere to reduce indirections.+ - Added versions of newBroadcastT*Chan for TMChan+ - Deprecated all the compatability stuff, since newBroadcastTChan requires stm >= 2.4 anyways. 2.0.0 (2013-05-12): - Add TQueue support
src/Control/Concurrent/STM/TBChan.hs view
@@ -5,7 +5,7 @@ {-# LANGUAGE Trustworthy #-} #endif ------------------------------------------------------------------- 2011.04.06+-- 2013.05.29 -- | -- Module : Control.Concurrent.STM.TBChan -- Copyright : Copyright (c) 2011--2013 wren ng thornton@@ -47,8 +47,8 @@ import Prelude hiding (reads) import Data.Typeable (Typeable) import Control.Monad.STM (STM, retry)-import Control.Concurrent.STM.TVar.Compat-import Control.Concurrent.STM.TChan.Compat -- N.B., GHC only+import Control.Concurrent.STM.TVar+import Control.Concurrent.STM.TChan -- N.B., GHC only -- N.B., we need a Custom cabal build-type for this to work. #ifdef __HADDOCK__@@ -59,7 +59,10 @@ -- | @TBChan@ is an abstract type representing a bounded FIFO -- channel.-data TBChan a = TBChan !(TVar Int) !(TVar Int) !(TChan a)+data TBChan a = TBChan+ {-# UNPACK #-} !(TVar Int)+ {-# UNPACK #-} !(TVar Int)+ {-# UNPACK #-} !(TChan a) deriving (Typeable) -- The components are: -- * How many free slots we /know/ we have available.
src/Control/Concurrent/STM/TBMChan.hs view
@@ -5,7 +5,7 @@ {-# LANGUAGE Trustworthy #-} #endif ------------------------------------------------------------------- 2011.04.06+-- 2013.05.29 -- | -- Module : Control.Concurrent.STM.TBMChan -- Copyright : Copyright (c) 2011--2013 wren ng thornton@@ -53,8 +53,8 @@ import Data.Typeable (Typeable) import Control.Applicative ((<$>)) import Control.Monad.STM (STM, retry)-import Control.Concurrent.STM.TVar.Compat-import Control.Concurrent.STM.TChan.Compat -- N.B., GHC only+import Control.Concurrent.STM.TVar+import Control.Concurrent.STM.TChan -- N.B., GHC only -- N.B., we need a Custom cabal build-type for this to work. #ifdef __HADDOCK__@@ -65,7 +65,11 @@ -- | @TBMChan@ is an abstract type representing a bounded closeable -- FIFO channel.-data TBMChan a = TBMChan !(TVar Bool) !(TVar Int) !(TVar Int) !(TChan a)+data TBMChan a = TBMChan+ {-# UNPACK #-} !(TVar Bool)+ {-# UNPACK #-} !(TVar Int)+ {-# UNPACK #-} !(TVar Int)+ {-# UNPACK #-} !(TChan a) deriving (Typeable) -- The components are: -- * Whether the channel has been closed.
src/Control/Concurrent/STM/TBMQueue.hs view
@@ -5,7 +5,7 @@ {-# LANGUAGE Trustworthy #-} #endif ------------------------------------------------------------------- 2013.05.12+-- 2013.05.29 -- | -- Module : Control.Concurrent.STM.TBMQueue -- Copyright : Copyright (c) 2011--2013 wren ng thornton@@ -17,9 +17,6 @@ -- A version of "Control.Concurrent.STM.TQueue" where the queue is -- bounded in length and closeable. This combines the abilities of -- "Control.Concurrent.STM.TBQueue" and "Control.Concurrent.STM.TMQueue".--- This variant incorporates ideas from Thomas M. DuBuisson's--- @bounded-tqueue@ package in order to reduce contention between--- readers and writers. -- -- /Since: 2.0.0/ ----------------------------------------------------------------@@ -54,8 +51,8 @@ import Data.Typeable (Typeable) import Control.Applicative ((<$>)) import Control.Monad.STM (STM, retry)-import Control.Concurrent.STM.TVar.Compat-import Control.Concurrent.STM.TQueue.Compat -- N.B., GHC only+import Control.Concurrent.STM.TVar+import Control.Concurrent.STM.TQueue -- N.B., GHC only -- N.B., we need a Custom cabal build-type for this to work. #ifdef __HADDOCK__@@ -66,7 +63,11 @@ -- | @TBMQueue@ is an abstract type representing a bounded closeable -- FIFO queue.-data TBMQueue a = TBMQueue !(TVar Bool) !(TVar Int) !(TVar Int) !(TQueue a)+data TBMQueue a = TBMQueue+ {-# UNPACK #-} !(TVar Bool)+ {-# UNPACK #-} !(TVar Int)+ {-# UNPACK #-} !(TVar Int)+ {-# UNPACK #-} !(TQueue a) deriving (Typeable) -- The components are: -- * Whether the queue has been closed.@@ -85,7 +86,7 @@ closed <- newTVar False slots <- newTVar n reads <- newTVar 0- queue <- newTQueue+ queue <- newTQueue return (TBMQueue closed slots reads queue) @@ -97,7 +98,7 @@ closed <- newTVarIO False slots <- newTVarIO n reads <- newTVarIO 0- queue <- newTQueueIO+ queue <- newTQueueIO return (TBMQueue closed slots reads queue)
src/Control/Concurrent/STM/TBQueue/Compat.hs view
@@ -5,7 +5,7 @@ {-# LANGUAGE Trustworthy #-} #endif ------------------------------------------------------------------- 2013.05.12+-- 2013.05.29 -- | -- Module : Control.Concurrent.STM.TBQueue.Compat -- Copyright : Copyright (c) 2011--2013 wren ng thornton@@ -19,13 +19,14 @@ -- @stm < 2.4.0@ lacks. This module uses Cabal-style CPP macros in -- order to use the package versions when available. ----- /Since: 2.0.0/+-- /Since: 2.0.0; Deprecated: 2.1.0 (will be removed in 3.0)/ ---------------------------------------------------------------- module Control.Concurrent.STM.TBQueue.Compat+ {-# DEPRECATED "stm-chans >= 2.1 requires stm >= 2.4; so this module no longer does anything useful." #-} ( -- * The TBQueue type- TBQueue+ TBQueue() -- ** Creating TBQueues , newTBQueue -- :: Int -> STM (TBQueue a) , newTBQueueIO -- :: Int -> IO (TBQueue a)@@ -47,14 +48,12 @@ import Data.Typeable import GHC.Conc -#define _UPK_(x) {-# UNPACK #-} !(x)- -- | 'TBQueue' is an abstract type representing a bounded FIFO channel.-data TBQueue a =- TBQueue _UPK_(TVar Int) -- CR: read capacity- _UPK_(TVar [a]) -- R: elements waiting to be read- _UPK_(TVar Int) -- CW: write capacity- _UPK_(TVar [a]) -- W: elements written (head is most recent)+data TBQueue a = TBQueue+ {-# UNPACK #-} !(TVar Int) -- CR: read capacity+ {-# UNPACK #-} !(TVar [a]) -- R: elements waiting to be read+ {-# UNPACK #-} !(TVar Int) -- CW: write capacity+ {-# UNPACK #-} !(TVar [a]) -- W: elements written (head is most recent) deriving Typeable instance Eq (TBQueue a) where
src/Control/Concurrent/STM/TChan/Compat.hs view
@@ -5,7 +5,7 @@ {-# LANGUAGE Trustworthy #-} #endif ------------------------------------------------------------------- 2012.02.29+-- 2013.05.29 -- | -- Module : Control.Concurrent.STM.TChan.Compat -- Copyright : Copyright (c) 2011--2013 wren ng thornton@@ -20,25 +20,30 @@ -- than the package versions due to the 'TChan' type being abstract. -- However, this module uses Cabal-style CPP macros in order to use -- the package versions when available.+--+-- /Deprecated: 2.1.0 (will be removed in 3.0)/ ---------------------------------------------------------------- module Control.Concurrent.STM.TChan.Compat+ {-# DEPRECATED "stm-chans >= 2.1 requires stm >= 2.4; so this module no longer does anything useful." #-} ( -- * The TChan type- TChan+ TChan() -- ** Creating TChans- , newTChan -- :: STM (TChan a)- , newTChanIO -- :: IO (TChan a)- , dupTChan -- :: TChan a -> STM (TChan a)+ , newTChan -- :: STM (TChan a)+ , newTChanIO -- :: IO (TChan a)+ , dupTChan -- :: TChan a -> STM (TChan a)+ , newBroadcastTChan -- :: STM (TChan a)+ , newBroadcastTChanIO -- :: IO (TChan a) -- ** Reading from TChans- , readTChan -- :: TChan a -> STM a- , tryReadTChan -- :: TChan a -> STM (Maybe a)- , peekTChan -- :: TChan a -> STM a- , tryPeekTChan -- :: TChan a -> STM (Maybe a)+ , readTChan -- :: TChan a -> STM a+ , tryReadTChan -- :: TChan a -> STM (Maybe a)+ , peekTChan -- :: TChan a -> STM a+ , tryPeekTChan -- :: TChan a -> STM (Maybe a) -- ** Writing to TChans- , unGetTChan -- :: TChan a -> a -> STM ()- , writeTChan -- :: TChan a -> a -> STM ()+ , unGetTChan -- :: TChan a -> a -> STM ()+ , writeTChan -- :: TChan a -> a -> STM () -- ** Predicates- , isEmptyTChan -- :: TChan a -> STM Bool+ , isEmptyTChan -- :: TChan a -> STM Bool ) where import Control.Concurrent.STM.TChan -- N.B., GHC only@@ -46,9 +51,14 @@ #if ! (MIN_VERSION_stm(2,3,0)) import Control.Applicative ((<$>)) import Control.Monad.STM (STM)+#endif+#if ! (MIN_VERSION_stm(2,4,0))+import Control.Monad.STM (STM)+import Control.Concurrent.STM.TVar+#endif -----------------------------------------------------------------+#if ! (MIN_VERSION_stm(2,3,0)) -- | A version of 'readTChan' which does not retry. Instead it -- returns @Nothing@ if no value is available. tryReadTChan :: TChan a -> STM (Maybe a)@@ -96,6 +106,49 @@ TCons a _ -> return (Just a) -} +#endif++----------------------------------------------------------------+#if ! (MIN_VERSION_stm(2,4,0))+-- BUG: how can we replicate this??++-- | Create a write-only 'TChan'. More precisely, 'readTChan' will+-- 'retry' even after items have been written to the channel. The+-- only way to read a broadcast channel is to duplicate it with+-- 'dupTChan'.+--+-- Consider a server that broadcasts messages to clients:+--+-- >serve :: TChan Message -> Client -> IO loop+-- >serve broadcastChan client = do+-- > myChan <- dupTChan broadcastChan+-- > forever $ do+-- > message <- readTChan myChan+-- > send client message+--+-- The problem with using 'newTChan' to create the broadcast channel+-- is that if it is only written to and never read, items will pile+-- up in memory. By using 'newBroadcastTChan' to create the broadcast+-- channel, items can be garbage collected after clients have seen+-- them.+newBroadcastTChan :: STM (TChan a)+newBroadcastTChan = do+ -- a la stm-2.4.2 (not stm-2.4 !)+ write_hole <- newTVar TNil+ read <- newTVar (error "reading from a TChan created by newBroadcastTChan; use dupTChan first")+ write <- newTVar write_hole+ return (TChan read write)+++-- | @IO@ version of 'newBroadcastTChan'.+newBroadcastTChanIO :: IO (TChan a)+newBroadcastTChanIO = do+ -- a la stm-2.4.2 (which is the same as stm-2.4 !!)+ dummy_hole <- newTVarIO TNil+ write_hole <- newTVarIO TNil+ read <- newTVarIO dummy_hole+ write <- newTVarIO write_hole+ return (TChan read write) #endif ----------------------------------------------------------------
src/Control/Concurrent/STM/TMChan.hs view
@@ -5,7 +5,7 @@ {-# LANGUAGE Trustworthy #-} #endif ------------------------------------------------------------------- 2012.02.12+-- 2013.05.29 -- | -- Module : Control.Concurrent.STM.TMChan -- Copyright : Copyright (c) 2011--2013 wren ng thornton@@ -27,6 +27,8 @@ , newTMChan , newTMChanIO , dupTMChan+ , newBroadcastTMChan+ , newBroadcastTMChanIO -- ** Reading from TMChans , readTMChan , tryReadTMChan@@ -45,8 +47,8 @@ import Data.Typeable (Typeable) import Control.Applicative ((<$>)) import Control.Monad.STM (STM)-import Control.Concurrent.STM.TVar.Compat-import Control.Concurrent.STM.TChan.Compat -- N.B., GHC only+import Control.Concurrent.STM.TVar+import Control.Concurrent.STM.TChan -- N.B., GHC only -- N.B., we need a Custom cabal build-type for this to work. #ifdef __HADDOCK__@@ -57,7 +59,9 @@ -- | @TMChan@ is an abstract type representing a closeable FIFO -- channel.-data TMChan a = TMChan !(TVar Bool) !(TChan a)+data TMChan a = TMChan+ {-# UNPACK #-} !(TVar Bool)+ {-# UNPACK #-} !(TChan a) deriving Typeable @@ -76,6 +80,26 @@ newTMChanIO = do closed <- newTVarIO False chan <- newTChanIO+ return (TMChan closed chan)+ ++-- | Like 'newBroadcastTChan'.+--+-- /Since: 2.1.0/+newBroadcastTMChan :: STM (TMChan a)+newBroadcastTMChan = do+ closed <- newTVar False+ chan <- newBroadcastTChan+ return (TMChan closed chan)+ ++-- | @IO@ version of 'newBroadcastTMChan'.+--+-- /Since: 2.1.0/+newBroadcastTMChanIO :: IO (TMChan a)+newBroadcastTMChanIO = do+ closed <- newTVarIO False+ chan <- newBroadcastTChanIO return (TMChan closed chan)
src/Control/Concurrent/STM/TMQueue.hs view
@@ -5,7 +5,7 @@ {-# LANGUAGE Trustworthy #-} #endif ------------------------------------------------------------------- 2013.05.12+-- 2013.05.29 -- | -- Module : Control.Concurrent.STM.TMQueue -- Copyright : Copyright (c) 2011--2013 wren ng thornton@@ -46,8 +46,8 @@ import Data.Typeable (Typeable) import Control.Applicative ((<$>)) import Control.Monad.STM (STM)-import Control.Concurrent.STM.TVar.Compat-import Control.Concurrent.STM.TQueue.Compat -- N.B., GHC only+import Control.Concurrent.STM.TVar+import Control.Concurrent.STM.TQueue -- N.B., GHC only -- N.B., we need a Custom cabal build-type for this to work. #ifdef __HADDOCK__@@ -58,7 +58,9 @@ -- | @TMQueue@ is an abstract type representing a closeable FIFO -- queue.-data TMQueue a = TMQueue !(TVar Bool) !(TQueue a)+data TMQueue a = TMQueue+ {-# UNPACK #-} !(TVar Bool)+ {-# UNPACK #-} !(TQueue a) deriving Typeable @@ -66,7 +68,7 @@ newTMQueue :: STM (TMQueue a) newTMQueue = do closed <- newTVar False- queue <- newTQueue+ queue <- newTQueue return (TMQueue closed queue) @@ -76,8 +78,9 @@ newTMQueueIO :: IO (TMQueue a) newTMQueueIO = do closed <- newTVarIO False- queue <- newTQueueIO+ queue <- newTQueueIO return (TMQueue closed queue)+ -- | Read the next value from the @TMQueue@, retrying if the queue -- is empty (and not closed). We return @Nothing@ immediately if
src/Control/Concurrent/STM/TMVar/Compat.hs view
@@ -5,7 +5,7 @@ {-# LANGUAGE Trustworthy #-} #endif ------------------------------------------------------------------- 2012.02.29+-- 2012.05.29 -- | -- Module : Control.Concurrent.STM.TMVar.Compat -- Copyright : Copyright (c) 2011--2013 wren ng thornton@@ -21,9 +21,10 @@ -- package, but we provide it anyways since we provide compatibility -- layers for @TVar@ and @TChan@. ----- /Since: 1.3.0/+-- /Since: 1.3.0; Deprecated: 2.1.0 (will be removed in 3.0)/ ---------------------------------------------------------------- module Control.Concurrent.STM.TMVar.Compat+ {-# DEPRECATED "stm-chans >= 2.1 requires stm >= 2.4; so this module no longer does anything useful." #-} ( -- * The TMVar type TMVar()
src/Control/Concurrent/STM/TQueue/Compat.hs view
@@ -5,7 +5,7 @@ {-# LANGUAGE Trustworthy #-} #endif ------------------------------------------------------------------- 2013.05.12+-- 2013.05.29 -- | -- Module : Control.Concurrent.STM.TQueue.Compat -- Copyright : Copyright (c) 2011--2013 wren ng thornton@@ -19,13 +19,14 @@ -- @stm < 2.4.0@ lacks. This module uses Cabal-style CPP macros in -- order to use the package versions when available. ----- /Since: 2.0.0/+-- /Since: 2.0.0; Deprecated: 2.1.0 (will be removed in 3.0)/ ---------------------------------------------------------------- module Control.Concurrent.STM.TQueue.Compat+ {-# DEPRECATED "stm-chans >= 2.1 requires stm >= 2.4; so this module no longer does anything useful." #-} ( -- * The TQueue type- TQueue+ TQueue() -- ** Creating TQueues , newTQueue -- :: STM (TQueue a) , newTQueueIO -- :: IO (TQueue a)@@ -49,8 +50,9 @@ -- | 'TQueue' is an abstract type representing an unbounded FIFO channel.-data TQueue a = TQueue {-# UNPACK #-} !(TVar [a])- {-# UNPACK #-} !(TVar [a])+data TQueue a = TQueue+ {-# UNPACK #-} !(TVar [a])+ {-# UNPACK #-} !(TVar [a]) deriving Typeable instance Eq (TQueue a) where
src/Control/Concurrent/STM/TVar/Compat.hs view
@@ -5,7 +5,7 @@ {-# LANGUAGE Trustworthy #-} #endif ------------------------------------------------------------------- 2012.02.29+-- 2012.05.29 -- | -- Module : Control.Concurrent.STM.TVar.Compat -- Copyright : Copyright (c) 2011--2013 wren ng thornton@@ -19,8 +19,11 @@ -- define 'modifyTVar', 'modifyTVar'', and 'swapTVar' which @stm < 2.3.0@ -- lacks. This module uses Cabal-style CPP macros in order to use -- the package versions when available.+--+-- /Deprecated: 2.1.0 (will be removed in 3.0)/ ---------------------------------------------------------------- module Control.Concurrent.STM.TVar.Compat+ {-# DEPRECATED "stm-chans >= 2.1 requires stm >= 2.4; so this module no longer does anything useful." #-} ( -- * The TVar type TVar()
stm-chans.cabal view
@@ -1,5 +1,5 @@ ------------------------------------------------------------------- wren ng thornton <wren@community.haskell.org> ~ 2013.05.12+-- wren ng thornton <wren@community.haskell.org> ~ 2013.05.29 ---------------------------------------------------------------- -- By and large Cabal >=1.2 is fine; but >= 1.6 gives tested-with:@@ -9,7 +9,7 @@ Build-Type: Custom Name: stm-chans-Version: 2.0.0+Version: 2.1.0 Stability: provisional Homepage: http://code.haskell.org/~wren/ Author: wren ng thornton, Thomas DuBuisson@@ -23,7 +23,7 @@ Description: Additional types of channels for STM. Tested-With:- GHC == 6.12.1, GHC == 6.12.3, GHC == 7.6.1+ GHC == 7.6.1 Extra-source-files: AUTHORS, README, VERSION Source-Repository head@@ -33,14 +33,14 @@ ---------------------------------------------------------------- Library -- N.B., the following versions are required for:- -- * stm >= 2.4: TQueue and TBQueue.+ -- * stm >= 2.4: T{,B}Queue and newBroadcastTChan{,IO} -- * stm >= 2.3.0: fast tryReadTChan, peekTChan, tryPeekTChan, -- tryReadTMVar, modifyTVar, modifyTVar', swapTVar. -- * stm >= 2.1.2: fast readTVarIO. -- -- Not sure what the real minbound is for base... Build-Depends: base >= 4.1 && < 5- , stm >= 2.1.1+ , stm >= 2.4 Hs-Source-Dirs: src Exposed-Modules: Control.Concurrent.STM.TBChan