{-# OPTIONS_GHC -fno-warn-unused-do-bind #-}
module Control.Concurrent.STM.MonadIO (
STM
, atomically
, always
, alwaysSucceeds
, retry
, orElse
, check
, catchSTM
, S.TVar
, newTVar
, readTVar
, writeTVar
, registerDelay
, modifyTVar
, modifyTVar_
, newTVarSTM
, readTVarSTM
, writeTVarSTM
, S.TMVar
, newTMVar
, newEmptyTMVar
, takeTMVar
, putTMVar
, readTMVar
, swapTMVar
, tryTakeTMVar
, tryPutTMVar
, isEmptyTMVar
, modifyTMVar
, modifyTMVar_
, newTMVarSTM
, newEmptyTMVarSTM
, takeTMVarSTM
, putTMVarSTM
, readTMVarSTM
, swapTMVarSTM
, tryTakeTMVarSTM
, tryPutTMVarSTM
, isEmptyTMVarSTM
)
where
import Control.Monad.STM hiding (atomically)
import qualified Control.Concurrent.STM as S
import Control.Concurrent.MonadIO
import GHC.Conc (readTVarIO)
atomically :: MonadIO io => STM a -> io a
atomically m = liftIO $ S.atomically m
type TVar = S.TVar
newTVar :: MonadIO io => a -> io (TVar a)
newTVar x = liftIO $ S.newTVarIO x
readTVar :: MonadIO io => TVar a -> io a
readTVar t = liftIO $ readTVarIO t
writeTVar :: MonadIO io => TVar a -> a -> io ()
writeTVar t x = atomically $ writeTVarSTM t x
registerDelay :: MonadIO io => Int -> io (TVar Bool)
registerDelay n = liftIO $ S.registerDelay n
modifyTVar :: MonadIO io => TVar a -> (a -> a) -> io (a,a)
modifyTVar t f = atomically $ do
x <- readTVarSTM t
let y = f x
seq y $ writeTVarSTM t y
return (x,y)
modifyTVar_ :: MonadIO io => TVar a -> (a -> a) -> io ()
modifyTVar_ t f = atomically $ do
x <- readTVarSTM t
let y = f x
seq y $ writeTVarSTM t y
newTVarSTM :: a -> STM (TVar a)
newTVarSTM x = S.newTVar x
readTVarSTM :: TVar a -> STM a
readTVarSTM t = S.readTVar t
writeTVarSTM :: TVar a -> a -> STM ()
writeTVarSTM t x = S.writeTVar t x
type TMVar a = S.TMVar a
newTMVar :: MonadIO io => a -> io (TMVar a)
newTMVar x = liftIO $ S.newTMVarIO x
newEmptyTMVar :: MonadIO io => io (TMVar a)
newEmptyTMVar = liftIO $ S.newEmptyTMVarIO
takeTMVar :: MonadIO io => TMVar a -> io a
takeTMVar t = atomically $ takeTMVarSTM t
putTMVar :: MonadIO io => TMVar a -> a -> io ()
putTMVar t x = atomically $ putTMVarSTM t x
readTMVar :: MonadIO io => TMVar a -> io a
readTMVar t = atomically $ readTMVarSTM t
swapTMVar :: MonadIO io => TMVar a -> a -> io a
swapTMVar t x = atomically $ swapTMVarSTM t x
tryTakeTMVar :: MonadIO io => TMVar a -> io (Maybe a)
tryTakeTMVar t = atomically $ tryTakeTMVarSTM t
tryPutTMVar :: MonadIO io => TMVar a -> a -> io Bool
tryPutTMVar t x = atomically $ tryPutTMVarSTM t x
isEmptyTMVar :: MonadIO io => TMVar a -> io Bool
isEmptyTMVar t = atomically $ isEmptyTMVarSTM t
modifyTMVar :: MonadIO io => TMVar a -> (a -> a) -> io (a,a)
modifyTMVar t f = atomically $ do
x <- takeTMVarSTM t
let y = f x
seq y $ putTMVarSTM t y
return (x,y)
modifyTMVar_ :: MonadIO io => TMVar a -> (a -> a) -> io ()
modifyTMVar_ t f = atomically $ do
x <- takeTMVarSTM t
let y = f x
seq y $ putTMVarSTM t y
newTMVarSTM :: a -> STM (TMVar a)
newTMVarSTM = S.newTMVar
newEmptyTMVarSTM :: STM (TMVar a)
newEmptyTMVarSTM = S.newEmptyTMVar
takeTMVarSTM :: TMVar a -> STM a
takeTMVarSTM = S.takeTMVar
putTMVarSTM :: TMVar a -> a -> STM ()
putTMVarSTM = S.putTMVar
readTMVarSTM :: TMVar a -> STM a
readTMVarSTM = S.readTMVar
swapTMVarSTM :: TMVar a -> a -> STM a
swapTMVarSTM = S.swapTMVar
tryTakeTMVarSTM :: TMVar a -> STM (Maybe a)
tryTakeTMVarSTM = S.tryTakeTMVar
tryPutTMVarSTM :: TMVar a -> a -> STM Bool
tryPutTMVarSTM = S.tryPutTMVar
isEmptyTMVarSTM :: TMVar a -> STM Bool
isEmptyTMVarSTM = S.isEmptyTMVar