packages feed

stm-chans 2.1.0 → 3.0.0

raw patch · 7 files changed

+5/−694 lines, 7 files

Files

VERSION view
@@ -1,4 +1,7 @@-2.1.0 (2013-XX-XX):+3.0.0 (2013-05-29):+    - Removed the deprecated compatability modules.++2.1.0 (2013-05-29):     - 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.
− src/Control/Concurrent/STM/TBQueue/Compat.hs
@@ -1,200 +0,0 @@-{-# OPTIONS_GHC -Wall -fwarn-tabs -fno-warn-name-shadowing #-}-{-# LANGUAGE CPP, DeriveDataTypeable #-}--#if __GLASGOW_HASKELL__ >= 701-{-# LANGUAGE Trustworthy #-}-#endif--------------------------------------------------------------------                                                    2013.05.29--- |--- Module      :  Control.Concurrent.STM.TBQueue.Compat--- Copyright   :  Copyright (c) 2011--2013 wren ng thornton--- License     :  BSD--- Maintainer  :  wren@community.haskell.org--- Stability   :  provisional--- Portability :  non-portable (CPP, STM, DeriveDataTypeable)------ Compatibility layer for older versions of the @stm@ library.--- Namely, we copy "Control.Concurrent.STM.TBQueue" module which--- @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; 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()-    -- ** Creating TBQueues-    , newTBQueue        -- :: Int -> STM (TBQueue a)-    , newTBQueueIO      -- :: Int -> IO (TBQueue a)-    -- ** Reading from TBQueues-    , readTBQueue       -- :: TBQueue a -> STM a-    , tryReadTBQueue    -- :: TBQueue a -> STM (Maybe a)-    , peekTBQueue       -- :: TBQueue a -> STM a-    , tryPeekTBQueue    -- :: TBQueue a -> STM (Maybe a)-    -- ** Writing to TBQueues-    , writeTBQueue      -- :: TBQueue a -> a -> STM ()-    , unGetTBQueue      -- :: TBQueue a -> a -> STM ()-    -- ** Predicates-    , isEmptyTBQueue    -- :: TBQueue a -> STM Bool-    ) where--#if MIN_VERSION_stm(2,4,0)-import Control.Concurrent.STM.TBQueue-#else-import Data.Typeable-import GHC.Conc---- | 'TBQueue' is an abstract type representing a bounded FIFO channel.-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-    TBQueue a _ _ _ == TBQueue b _ _ _ = a == b----- Total channel capacity remaining is CR + CW. Reads only need to--- access CR, writes usually need to access only CW but sometimes need--- CR.  So in the common case we avoid contention between CR and CW.------   - when removing an element from R:---     CR := CR + 1------   - when adding an element to W:---     if CW is non-zero---         then CW := CW - 1---         then if CR is non-zero---                 then CW := CR - 1; CR := 0---                 else **FULL**----- | Build and returns a new instance of 'TBQueue'.-newTBQueue-    :: Int   -- ^ maximum number of elements the queue can hold-    -> STM (TBQueue a)-newTBQueue size = do-    read  <- newTVar []-    write <- newTVar []-    rsize <- newTVar 0-    wsize <- newTVar size-    return (TBQueue rsize read wsize write)----- | @IO@ version of 'newTBQueue'. This is useful for creating--- top-level 'TBQueue's using 'System.IO.Unsafe.unsafePerformIO',--- because using 'atomically' inside 'System.IO.Unsafe.unsafePerformIO'--- isn't possible.-newTBQueueIO :: Int -> IO (TBQueue a)-newTBQueueIO size = do-    read  <- newTVarIO []-    write <- newTVarIO []-    rsize <- newTVarIO 0-    wsize <- newTVarIO size-    return (TBQueue rsize read wsize write)----- | Write a value to a 'TBQueue'; blocks if the queue is full.-writeTBQueue :: TBQueue a -> a -> STM ()-writeTBQueue (TBQueue rsize _read wsize write) a = do-    w <- readTVar wsize-    if w /= 0-        then writeTVar wsize (w - 1)-        else do-            r <- readTVar rsize-            if r /= 0-                then do-                    writeTVar rsize 0-                    writeTVar wsize (r - 1)-                else retry-    listend <- readTVar write-    writeTVar write (a:listend)----- | Read the next value from the 'TBQueue'.-readTBQueue :: TBQueue a -> STM a-readTBQueue (TBQueue rsize read _wsize write) = do-    xs <- readTVar read-    r <- readTVar rsize-    writeTVar rsize (r + 1)-    case xs of-        (x:xs') -> do-            writeTVar read xs'-            return x-        [] -> do-            ys <- readTVar write-            case ys of-                [] -> retry-                _  -> do-                    let (z:zs) = reverse ys-                        -- N.B., lazy: we want the transaction to-                        -- be short, otherwise it will conflict.-                    writeTVar write []-                    writeTVar read zs-                    return z----- | A version of 'readTBQueue' which does not retry. Instead it--- returns @Nothing@ if no value is available.-tryReadTBQueue :: TBQueue a -> STM (Maybe a)-tryReadTBQueue c = fmap Just (readTBQueue c) `orElse` return Nothing----- | Get the next value from the @TBQueue@ without removing it,--- retrying if the channel is empty.-peekTBQueue :: TBQueue a -> STM a-peekTBQueue c = do-    x <- readTBQueue c-    unGetTBQueue c x-    return x----- | A version of 'peekTBQueue' which does not retry. Instead it--- returns @Nothing@ if no value is available.-tryPeekTBQueue :: TBQueue a -> STM (Maybe a)-tryPeekTBQueue c = do-    m <- tryReadTBQueue c-    case m of-        Nothing -> return Nothing-        Just x  -> do-            unGetTBQueue c x-            return m----- | Put a data item back onto a channel, where it will be the next--- item read. Blocks if the queue is full.-unGetTBQueue :: TBQueue a -> a -> STM ()-unGetTBQueue (TBQueue rsize read wsize _write) a = do-    r <- readTVar rsize-    if r > 0-        then writeTVar rsize (r - 1)-        else do-            w <- readTVar wsize-            if w > 0-                then writeTVar wsize (w - 1)-                else retry-    xs <- readTVar read-    writeTVar read (a:xs)----- | Returns 'True' if the supplied 'TBQueue' is empty.-isEmptyTBQueue :: TBQueue a -> STM Bool-isEmptyTBQueue (TBQueue _rsize read _wsize write) = do-    xs <- readTVar read-    case xs of-        (_:_) -> return False-        []    -> do-            ys <- readTVar write-            case ys of-                [] -> return True-                _  -> return False-#endif------------------------------------------------------------------------------------------------------------------------------ fin.
− src/Control/Concurrent/STM/TChan/Compat.hs
@@ -1,155 +0,0 @@-{-# OPTIONS_GHC -Wall -fwarn-tabs #-}-{-# LANGUAGE CPP #-}--#if __GLASGOW_HASKELL__ >= 701-{-# LANGUAGE Trustworthy #-}-#endif--------------------------------------------------------------------                                                    2013.05.29--- |--- Module      :  Control.Concurrent.STM.TChan.Compat--- Copyright   :  Copyright (c) 2011--2013 wren ng thornton--- License     :  BSD--- Maintainer  :  wren@community.haskell.org--- Stability   :  provisional--- Portability :  non-portable (GHC STM, CPP)------ Compatibility layer for older versions of the @stm@ library.--- Namely, we define 'tryReadTChan', 'peekTChan', and 'tryPeekTChan'--- which @stm < 2.3.0@ lacks. These implementations are less efficient--- 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()-    -- ** Creating TChans-    , 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)-    -- ** Writing to TChans-    , unGetTChan            -- :: TChan a -> a -> STM ()-    , writeTChan            -- :: TChan a -> a -> STM ()-    -- ** Predicates-    , isEmptyTChan          -- :: TChan a -> STM Bool-    ) where--import Control.Concurrent.STM.TChan -- N.B., GHC only--#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)-tryReadTChan chan = do-    b <- isEmptyTChan chan-    if b then return Nothing else Just <$> readTChan chan-{- -- The optimized implementation in stm-2.3.0-tryReadTChan (TChan read _write) = do-    hd <- readTVar =<< readTVar read-    case hd of-        TNil       -> return Nothing-        TCons a tl -> do-            writeTVar read tl-            return (Just a)--}----- | Get the next value from the @TChan@ without removing it,--- retrying if the channel is empty.-peekTChan :: TChan a -> STM a-peekTChan chan = do-    x <- readTChan chan-    unGetTChan chan x-    return x-{- -- The optimized implementation in stm-2.3.0-peekTChan (TChan read _write) = do-    hd <- readTVar =<< readTVar read-    case hd of-        TNil      -> retry-        TCons a _ -> return a--}----- | A version of 'peekTChan' which does not retry. Instead it--- returns @Nothing@ if no value is available.-tryPeekTChan :: TChan a -> STM (Maybe a)-tryPeekTChan chan = do-    b <- isEmptyTChan chan-    if b then return Nothing else Just <$> peekTChan chan-{- -- The optimized implementation in stm-2.3.0-tryPeekTChan (TChan read _write) = do-    hd <- readTVar =<< readTVar read-    case hd of-        TNil      -> return Nothing-        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------------------------------------------------------------------------------------------------------------------------------ fin.
− src/Control/Concurrent/STM/TMVar/Compat.hs
@@ -1,72 +0,0 @@-{-# OPTIONS_GHC -Wall -fwarn-tabs #-}-{-# LANGUAGE CPP #-}--#if __GLASGOW_HASKELL__ >= 701-{-# LANGUAGE Trustworthy #-}-#endif--------------------------------------------------------------------                                                    2012.05.29--- |--- Module      :  Control.Concurrent.STM.TMVar.Compat--- Copyright   :  Copyright (c) 2011--2013 wren ng thornton--- License     :  BSD--- Maintainer  :  wren@community.haskell.org--- Stability   :  provisional--- Portability :  non-portable (STM, CPP)------ Compatibility layer for older versions of the @stm@ library.--- Namely, we define 'tryReadTMVar' which @stm < 2.3.0@ lacks. This--- module uses Cabal-style CPP macros in order to use the package--- versions when available. This isn't actually used by the @stm-chans@--- package, but we provide it anyways since we provide compatibility--- layers for @TVar@ and @TChan@.------ /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()-    -- ** Creating TMVars-    , newTMVar          -- :: a -> STM (TMVar a)-    , newTMVarIO        -- :: a -> IO  (TMVar a)-    , newEmptyTMVar     -- :: STM (TMVar a)-    , newEmptyTMVarIO   -- :: IO  (TMVar a)-    -- ** Reading from TMVars-    , readTMVar         -- :: TMVar a -> STM a-    , tryReadTMVar      -- :: TMVar a -> STM (Maybe a)-    , takeTMVar         -- :: TMVar a -> STM a-    , tryTakeTMVar      -- :: TMVar a -> STM (Maybe a)-    -- ** Writing to TMVars-    , putTMVar          -- :: TMVar a -> a -> STM ()-    , tryPutTMVar       -- :: TMVar a -> a -> STM Bool-    , swapTMVar         -- :: TMVar a -> a -> STM a-    -- TODO: make another patch for trySwapTMVar?-    -- ** Other capabilities-    , isEmptyTMVar      -- :: TMVar a -> STM Bool-    ) where--import Control.Concurrent.STM.TMVar--#if ! (MIN_VERSION_stm(2,3,0))-import Control.Concurrent.STM (STM)--------------------------------------------------------------------- | A version of 'readTMVar' which does not retry. Instead it--- returns @Nothing@ if no value is available.-tryReadTMVar :: TMVar a -> STM (Maybe a)-tryReadTMVar var = do-    m <- tryTakeTMVar var-    case m of-        Nothing -> return Nothing-        Just x  -> putTMVar var x >> return (Just x)-{- -- The optimized implementation in stm-2.3.0-tryReadTMVar (TMVar t) = readTVar t-{-# INLINE tryReadTMVar #-}--}--#endif------------------------------------------------------------------------------------------------------------------------------ fin.
− src/Control/Concurrent/STM/TQueue/Compat.hs
@@ -1,158 +0,0 @@-{-# OPTIONS_GHC -Wall -fwarn-tabs -fno-warn-name-shadowing #-}-{-# LANGUAGE CPP, DeriveDataTypeable #-}--#if __GLASGOW_HASKELL__ >= 701-{-# LANGUAGE Trustworthy #-}-#endif--------------------------------------------------------------------                                                    2013.05.29--- |--- Module      :  Control.Concurrent.STM.TQueue.Compat--- Copyright   :  Copyright (c) 2011--2013 wren ng thornton--- License     :  BSD--- Maintainer  :  wren@community.haskell.org--- Stability   :  provisional--- Portability :  non-portable (CPP, STM, DeriveDataTypeable)------ Compatibility layer for older versions of the @stm@ library.--- Namely, we copy "Control.Concurrent.STM.TQueue" module which--- @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; 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()-    -- ** Creating TQueues-    , newTQueue     -- :: STM (TQueue a)-    , newTQueueIO   -- :: IO (TQueue a)-    -- ** Reading from TQueues-    , readTQueue    -- :: TQueue a -> STM a-    , tryReadTQueue -- :: TQueue a -> STM (Maybe a)-    , peekTQueue    -- :: TQueue a -> STM a-    , tryPeekTQueue -- :: TQueue a -> STM (Maybe a)-    -- ** Writing to TQueues-    , writeTQueue   -- :: TQueue a -> a -> STM ()-    , unGetTQueue   -- :: TQueue a -> a -> STM ()-    -- ** Predicates-    , isEmptyTQueue -- :: TQueue a -> STM Bool-    ) where--#if MIN_VERSION_stm(2,4,0)-import Control.Concurrent.STM.TQueue-#else-import GHC.Conc-import Data.Typeable (Typeable)----- | 'TQueue' is an abstract type representing an unbounded FIFO channel.-data TQueue a = TQueue-    {-# UNPACK #-} !(TVar [a])-    {-# UNPACK #-} !(TVar [a])-    deriving Typeable--instance Eq (TQueue a) where-    TQueue a _ == TQueue b _ = a == b----- | Build and returns a new instance of 'TQueue'.-newTQueue :: STM (TQueue a)-newTQueue = do-    read  <- newTVar []-    write <- newTVar []-    return (TQueue read write)----- | @IO@ version of 'newTQueue'. This is useful for creating--- top-level 'TQueue's using 'System.IO.Unsafe.unsafePerformIO',--- because using 'atomically' inside 'System.IO.Unsafe.unsafePerformIO'--- isn't possible.-newTQueueIO :: IO (TQueue a)-newTQueueIO = do-    read  <- newTVarIO []-    write <- newTVarIO []-    return (TQueue read write)----- | Write a value to a 'TQueue'.-writeTQueue :: TQueue a -> a -> STM ()-writeTQueue (TQueue _read write) a = do-    listend <- readTVar write-    writeTVar write (a:listend)----- | Read the next value from the 'TQueue'.-readTQueue :: TQueue a -> STM a-readTQueue (TQueue read write) = do-    xs <- readTVar read-    case xs of-        (x:xs') -> do-            writeTVar read xs'-            return x-        [] -> do-            ys <- readTVar write-            case ys of-                [] -> retry-                _  ->-                    case reverse ys of-                    []     -> error "readTQueue"-                    (z:zs) -> do-                        writeTVar write []-                        writeTVar read zs-                        return z----- | A version of 'readTQueue' which does not retry. Instead it--- returns @Nothing@ if no value is available.-tryReadTQueue :: TQueue a -> STM (Maybe a)-tryReadTQueue c = fmap Just (readTQueue c) `orElse` return Nothing----- | Get the next value from the @TQueue@ without removing it,--- retrying if the channel is empty.-peekTQueue :: TQueue a -> STM a-peekTQueue c = do-    x <- readTQueue c-    unGetTQueue c x-    return x----- | A version of 'peekTQueue' which does not retry. Instead it--- returns @Nothing@ if no value is available.-tryPeekTQueue :: TQueue a -> STM (Maybe a)-tryPeekTQueue c = do-    m <- tryReadTQueue c-    case m of-        Nothing -> return Nothing-        Just x  -> do-            unGetTQueue c x-            return m----- | Put a data item back onto a channel, where it will be the next--- item read.-unGetTQueue :: TQueue a -> a -> STM ()-unGetTQueue (TQueue read _write) a = do-    xs <- readTVar read-    writeTVar read (a:xs)----- | Returns 'True' if the supplied 'TQueue' is empty.-isEmptyTQueue :: TQueue a -> STM Bool-isEmptyTQueue (TQueue read write) = do-    xs <- readTVar read-    case xs of-        (_:_) -> return False-        [] -> do-            ys <- readTVar write-            case ys of-                [] -> return True-                _  -> return False-#endif------------------------------------------------------------------------------------------------------------------------------ fin.
− src/Control/Concurrent/STM/TVar/Compat.hs
@@ -1,102 +0,0 @@-{-# OPTIONS_GHC -Wall -fwarn-tabs #-}-{-# LANGUAGE CPP #-}--#if __GLASGOW_HASKELL__ >= 701-{-# LANGUAGE Trustworthy #-}-#endif--------------------------------------------------------------------                                                    2012.05.29--- |--- Module      :  Control.Concurrent.STM.TVar.Compat--- Copyright   :  Copyright (c) 2011--2013 wren ng thornton--- License     :  BSD--- Maintainer  :  wren@community.haskell.org--- Stability   :  provisional--- Portability :  non-portable (STM, CPP)------ Compatibility layer for older versions of the @stm@ library.--- Namely, we define 'readTVarIO' which @stm < 2.1.2@ lacks; and we--- 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()-    -- ** Creating TVars-    , newTVar       -- :: a -> STM (TVar a)-    , newTVarIO     -- :: a -> IO  (TVar a)-    -- ** Reading from TVars-    , readTVar      -- :: TVar a -> STM a-    , readTVarIO    -- :: TVar a -> IO  a-    -- ** Writing to TVars-    , writeTVar     -- :: TVar a -> a -> STM ()-    , modifyTVar    -- :: TVar a -> (a -> a) -> STM ()-    , modifyTVar'   -- :: TVar a -> (a -> a) -> STM ()-    , swapTVar      -- :: TVar a -> a -> STM a-    -- ** Other capabilities-    , registerDelay -- :: Int -> IO (TVar Bool)-    ) where--import Control.Concurrent.STM.TVar--#if ! (MIN_VERSION_stm(2,1,2))-import Control.Concurrent.STM (atomically)-#endif--#if ! (MIN_VERSION_stm(2,3,0))-import Control.Concurrent.STM (STM)-#endif-------------------------------------------------------------------#if ! (MIN_VERSION_stm(2,1,2))--- | Return the current value stored in a TVar. This is equivalent to------ > readTVarIO = atomically . readTVar------ but works much faster (on @stm >= 2.1.2@), because it doesn't--- perform a complete transaction, it just reads the current value--- of the TVar.-readTVarIO :: TVar a -> IO a-readTVarIO = atomically . readTVar-{-# INLINE readTVarIO #-}-#endif---#if ! (MIN_VERSION_stm(2,3,0))---- Like 'modifyIORef' but for @TVar@.--- | Mutate the contents of a @TVar@. /N.B./, this version is--- non-strict.-modifyTVar :: TVar a -> (a -> a) -> STM ()-modifyTVar var f = do-    x <- readTVar var-    writeTVar var (f x)-{-# INLINE modifyTVar #-}----- | Strict version of 'modifyTVar'.-modifyTVar' :: TVar a -> (a -> a) -> STM ()-modifyTVar' var f = do-    x <- readTVar var-    writeTVar var $! f x-{-# INLINE modifyTVar' #-}----- Like 'swapTMVar' but for @TVar@.--- | Swap the contents of a @TVar@ for a new value.-swapTVar :: TVar a -> a -> STM a-swapTVar var new = do-    old <- readTVar var-    writeTVar var new-    return old-{-# INLINE swapTVar #-}--#endif------------------------------------------------------------------------------------------------------------------------------ fin.
stm-chans.cabal view
@@ -9,7 +9,7 @@ Build-Type:     Custom  Name:           stm-chans-Version:        2.1.0+Version:        3.0.0 Stability:      provisional Homepage:       http://code.haskell.org/~wren/ Author:         wren ng thornton, Thomas DuBuisson@@ -48,11 +48,6 @@                    , Control.Concurrent.STM.TMChan                    , Control.Concurrent.STM.TBMQueue                    , Control.Concurrent.STM.TMQueue-                   , Control.Concurrent.STM.TChan.Compat-                   , Control.Concurrent.STM.TQueue.Compat-                   , Control.Concurrent.STM.TBQueue.Compat-                   , Control.Concurrent.STM.TMVar.Compat-                   , Control.Concurrent.STM.TVar.Compat  ---------------------------------------------------------------- ----------------------------------------------------------- fin.