Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
This module corresponds to STM
in "stm" package
Synopsis
- throwSTM :: forall (m :: Type -> Type) e a. (MonadSTM m, MonadThrow (STM m), Exception e) => e -> STM m a
- type family STM (m :: Type -> Type) = (stm :: Type -> Type) | stm -> m
- class (Monad m, Monad (STM m)) => MonadSTM (m :: Type -> Type) where
- class MonadSTM m => MonadLabelledSTM (m :: Type -> Type)
- type family InspectMonad (m :: Type -> Type) :: Type -> Type
- class (MonadSTM m, Monad (InspectMonad m)) => MonadInspectSTM (m :: Type -> Type) where
- type InspectMonad (m :: Type -> Type) :: Type -> Type
- inspectTVar :: proxy m -> TVar m a -> InspectMonad m a
- inspectTMVar :: proxy m -> TMVar m a -> InspectMonad m (Maybe a)
- data TraceValue where
- TraceValue :: forall tr. Typeable tr => {..} -> TraceValue
- pattern TraceDynamic :: () => Typeable tr => tr -> TraceValue
- pattern TraceString :: String -> TraceValue
- pattern DontTrace :: TraceValue
- class MonadInspectSTM m => MonadTraceSTM (m :: Type -> Type) where
- traceTSem :: proxy m -> TSem m -> (Maybe Integer -> Integer -> InspectMonad m TraceValue) -> STM m ()
- traceTSemIO :: TSem m -> (Maybe Integer -> Integer -> InspectMonad m TraceValue) -> m ()
- data StrictTArray m i e
- type LazyTArray m = TArray m
- fromLazyTArray :: LazyTArray m i e -> StrictTArray m i e
- data StrictTBQueue m a
- type LazyTBQueue m = TBQueue m
- fromLazyTBQueue :: LazyTBQueue m a -> StrictTBQueue m a
- castStrictTBQueue :: LazyTBQueue m ~ LazyTBQueue n => StrictTBQueue m a -> StrictTBQueue n a
- labelTBQueue :: MonadLabelledSTM m => StrictTBQueue m a -> String -> STM m ()
- labelTBQueueIO :: MonadLabelledSTM m => StrictTBQueue m a -> String -> m ()
- traceTBQueue :: MonadTraceSTM m => proxy m -> StrictTBQueue m a -> (Maybe [a] -> [a] -> InspectMonad m TraceValue) -> STM m ()
- traceTBQueueIO :: MonadTraceSTM m => StrictTBQueue m a -> (Maybe [a] -> [a] -> InspectMonad m TraceValue) -> m ()
- newTBQueue :: MonadSTM m => Natural -> STM m (StrictTBQueue m a)
- newTBQueueIO :: MonadSTM m => Natural -> m (StrictTBQueue m a)
- readTBQueue :: MonadSTM m => StrictTBQueue m a -> STM m a
- tryReadTBQueue :: MonadSTM m => StrictTBQueue m a -> STM m (Maybe a)
- peekTBQueue :: MonadSTM m => StrictTBQueue m a -> STM m a
- tryPeekTBQueue :: MonadSTM m => StrictTBQueue m a -> STM m (Maybe a)
- flushTBQueue :: MonadSTM m => StrictTBQueue m a -> STM m [a]
- writeTBQueue :: MonadSTM m => StrictTBQueue m a -> a -> STM m ()
- lengthTBQueue :: MonadSTM m => StrictTBQueue m a -> STM m Natural
- isEmptyTBQueue :: MonadSTM m => StrictTBQueue m a -> STM m Bool
- isFullTBQueue :: MonadSTM m => StrictTBQueue m a -> STM m Bool
- unGetTBQueue :: MonadSTM m => StrictTBQueue m a -> a -> STM m ()
- data StrictTChan m a
- type LazyTChan m = TChan m
- fromLazyTChan :: LazyTChan m a -> StrictTChan m a
- castStrictTChan :: LazyTChan m ~ LazyTChan n => StrictTChan m a -> StrictTChan n a
- newTChan :: MonadSTM m => STM m (StrictTChan m a)
- newBroadcastTChan :: MonadSTM m => STM m (StrictTChan m a)
- writeTChan :: MonadSTM m => StrictTChan m a -> a -> STM m ()
- readTChan :: MonadSTM m => StrictTChan m a -> STM m a
- tryReadTChan :: MonadSTM m => StrictTChan m a -> STM m (Maybe a)
- peekTChan :: MonadSTM m => StrictTChan m a -> STM m a
- tryPeekTChan :: MonadSTM m => StrictTChan m a -> STM m (Maybe a)
- dupTChan :: MonadSTM m => StrictTChan m a -> STM m (StrictTChan m a)
- unGetTChan :: MonadSTM m => StrictTChan m a -> a -> STM m ()
- isEmptyTChan :: MonadSTM m => StrictTChan m a -> STM m Bool
- cloneTChan :: MonadSTM m => StrictTChan m a -> STM m (StrictTChan m a)
- data StrictTMVar m a
- type LazyTMVar m = TMVar m
- fromLazyTMVar :: LazyTMVar m a -> StrictTMVar m a
- labelTMVar :: MonadLabelledSTM m => StrictTMVar m a -> String -> STM m ()
- labelTMVarIO :: MonadLabelledSTM m => StrictTMVar m a -> String -> m ()
- traceTMVar :: MonadTraceSTM m => proxy m -> StrictTMVar m a -> (Maybe (Maybe a) -> Maybe a -> InspectMonad m TraceValue) -> STM m ()
- traceTMVarIO :: MonadTraceSTM m => StrictTMVar m a -> (Maybe (Maybe a) -> Maybe a -> InspectMonad m TraceValue) -> m ()
- castStrictTMVar :: LazyTMVar m ~ LazyTMVar n => StrictTMVar m a -> StrictTMVar n a
- newTMVar :: MonadSTM m => a -> STM m (StrictTMVar m a)
- newTMVarIO :: MonadSTM m => a -> m (StrictTMVar m a)
- newEmptyTMVar :: MonadSTM m => STM m (StrictTMVar m a)
- newEmptyTMVarIO :: MonadSTM m => m (StrictTMVar m a)
- takeTMVar :: MonadSTM m => StrictTMVar m a -> STM m a
- tryTakeTMVar :: MonadSTM m => StrictTMVar m a -> STM m (Maybe a)
- putTMVar :: MonadSTM m => StrictTMVar m a -> a -> STM m ()
- tryPutTMVar :: MonadSTM m => StrictTMVar m a -> a -> STM m Bool
- readTMVar :: MonadSTM m => StrictTMVar m a -> STM m a
- tryReadTMVar :: MonadSTM m => StrictTMVar m a -> STM m (Maybe a)
- swapTMVar :: MonadSTM m => StrictTMVar m a -> a -> STM m a
- isEmptyTMVar :: MonadSTM m => StrictTMVar m a -> STM m Bool
- data StrictTQueue m a
- type LazyTQueue m = TQueue m
- fromLazyTQueue :: LazyTQueue m a -> StrictTQueue m a
- castStrictTQueue :: LazyTQueue m ~ LazyTQueue n => StrictTQueue m a -> StrictTQueue n a
- labelTQueue :: MonadLabelledSTM m => StrictTQueue m a -> String -> STM m ()
- labelTQueueIO :: MonadLabelledSTM m => StrictTQueue m a -> String -> m ()
- traceTQueue :: MonadTraceSTM m => proxy m -> StrictTQueue m a -> (Maybe [a] -> [a] -> InspectMonad m TraceValue) -> STM m ()
- traceTQueueIO :: MonadTraceSTM m => StrictTQueue m a -> (Maybe [a] -> [a] -> InspectMonad m TraceValue) -> m ()
- newTQueue :: MonadSTM m => STM m (StrictTQueue m a)
- newTQueueIO :: MonadSTM m => m (StrictTQueue m a)
- readTQueue :: MonadSTM m => StrictTQueue m a -> STM m a
- tryReadTQueue :: MonadSTM m => StrictTQueue m a -> STM m (Maybe a)
- peekTQueue :: MonadSTM m => StrictTQueue m a -> STM m a
- tryPeekTQueue :: MonadSTM m => StrictTQueue m a -> STM m (Maybe a)
- flushTQueue :: MonadSTM m => StrictTQueue m a -> STM m [a]
- writeTQueue :: MonadSTM m => StrictTQueue m a -> a -> STM m ()
- isEmptyTQueue :: MonadSTM m => StrictTQueue m a -> STM m Bool
- unGetTQueue :: MonadSTM m => StrictTQueue m a -> a -> STM m ()
- data StrictTVar m a
- type LazyTVar m = TVar m
- labelTVar :: MonadLabelledSTM m => StrictTVar m a -> String -> STM m ()
- labelTVarIO :: MonadLabelledSTM m => StrictTVar m a -> String -> m ()
- traceTVar :: MonadTraceSTM m => proxy m -> StrictTVar m a -> (Maybe a -> a -> InspectMonad m TraceValue) -> STM m ()
- traceTVarIO :: MonadTraceSTM m => StrictTVar m a -> (Maybe a -> a -> InspectMonad m TraceValue) -> m ()
- castStrictTVar :: LazyTVar m ~ LazyTVar n => StrictTVar m a -> StrictTVar n a
- toLazyTVar :: StrictTVar m a -> LazyTVar m a
- fromLazyTVar :: LazyTVar m a -> StrictTVar m a
- newTVar :: MonadSTM m => a -> STM m (StrictTVar m a)
- newTVarIO :: MonadSTM m => a -> m (StrictTVar m a)
- newTVarWithInvariant :: (MonadSTM m, HasCallStack) => (a -> Maybe String) -> a -> STM m (StrictTVar m a)
- newTVarWithInvariantIO :: (MonadSTM m, HasCallStack) => (a -> Maybe String) -> a -> m (StrictTVar m a)
- readTVar :: MonadSTM m => StrictTVar m a -> STM m a
- readTVarIO :: MonadSTM m => StrictTVar m a -> m a
- writeTVar :: (MonadSTM m, HasCallStack) => StrictTVar m a -> a -> STM m ()
- modifyTVar :: MonadSTM m => StrictTVar m a -> (a -> a) -> STM m ()
- stateTVar :: MonadSTM m => StrictTVar m s -> (s -> (a, s)) -> STM m a
- swapTVar :: MonadSTM m => StrictTVar m a -> a -> STM m a
- checkInvariant :: HasCallStack => Maybe String -> a -> a
Documentation
throwSTM :: forall (m :: Type -> Type) e a. (MonadSTM m, MonadThrow (STM m), Exception e) => e -> STM m a #
throwIO
specialised to stm
monad.
class (Monad m, Monad (STM m)) => MonadSTM (m :: Type -> Type) where #
The STM primitives parametrised by a monad m
.
atomically, newTVar, readTVar, writeTVar, retry, orElse, newTMVar, newEmptyTMVar, takeTMVar, tryTakeTMVar, putTMVar, tryPutTMVar, readTMVar, tryReadTMVar, swapTMVar, isEmptyTMVar, newTQueue, readTQueue, tryReadTQueue, peekTQueue, tryPeekTQueue, flushTQueue, writeTQueue, isEmptyTQueue, unGetTQueue, newTBQueue, readTBQueue, tryReadTBQueue, peekTBQueue, tryPeekTBQueue, flushTBQueue, writeTBQueue, lengthTBQueue, isEmptyTBQueue, isFullTBQueue, unGetTBQueue, newTSem, waitTSem, signalTSem, signalTSemN, newTChan, newBroadcastTChan, dupTChan, cloneTChan, readTChan, tryReadTChan, peekTChan, tryPeekTChan, writeTChan, unGetTChan, isEmptyTChan
atomically :: HasCallStack => STM m a -> m a #
Atomically run an STM computation.
See atomically
.
See retry
.
orElse :: STM m a -> STM m a -> STM m a #
See orElse
.
See check
.
Instances
class MonadSTM m => MonadLabelledSTM (m :: Type -> Type) #
Labelled TVar
s & friends.
The IO
instances is no-op, the IOSim
instance enhances simulation trace.
This is very useful when analysing low lever concurrency issues (e.g.
deadlocks, livelocks etc).
Instances
MonadLabelledSTM IO | noop instance |
Defined in Control.Monad.Class.MonadSTM.Internal labelTVar :: TVar IO a -> String -> STM IO () # labelTMVar :: TMVar IO a -> String -> STM IO () # labelTQueue :: TQueue IO a -> String -> STM IO () # labelTBQueue :: TBQueue IO a -> String -> STM IO () # labelTArray :: (Ix i, Show i) => TArray IO i e -> String -> STM IO () # labelTSem :: TSem IO -> String -> STM IO () # labelTChan :: TChan IO a -> String -> STM IO () # labelTVarIO :: TVar IO a -> String -> IO () # labelTMVarIO :: TMVar IO a -> String -> IO () # labelTQueueIO :: TQueue IO a -> String -> IO () # labelTBQueueIO :: TBQueue IO a -> String -> IO () # labelTArrayIO :: (Ix i, Show i) => TArray IO i e -> String -> IO () # |
type family InspectMonad (m :: Type -> Type) :: Type -> Type #
Instances
type InspectMonad IO | |
Defined in Control.Monad.Class.MonadSTM.Internal |
class (MonadSTM m, Monad (InspectMonad m)) => MonadInspectSTM (m :: Type -> Type) where #
This type class is indented for
'io-sim', where one might want
to access a TVar
in the underlying ST
monad.
inspectTVar :: proxy m -> TVar m a -> InspectMonad m a #
Return the value of a TVar
as an InspectMonad
computation.
inspectTVar
is useful if the value of a TVar
observed by traceTVar
contains other TVar
s.
inspectTMVar :: proxy m -> TMVar m a -> InspectMonad m (Maybe a) #
Return the value of a MonadSTM
as an InspectMonad
computation.
Instances
MonadInspectSTM IO | |
Defined in Control.Monad.Class.MonadSTM.Internal type InspectMonad IO :: Type -> Type # inspectTVar :: proxy IO -> TVar IO a -> InspectMonad IO a # inspectTMVar :: proxy IO -> TMVar IO a -> InspectMonad IO (Maybe a) # |
data TraceValue where #
A GADT which instructs how to trace the value. The traceDynamic
will
use dynamic tracing, e.g. "Control.Monad.IOSim.traceM"; while traceString
will be traced with EventSay
. The IOSim
s dynamic tracing allows to
recover the value from the simulation trace (see
"Control.Monad.IOSim.selectTraceEventsDynamic").
TraceValue | |
|
pattern TraceDynamic :: () => Typeable tr => tr -> TraceValue | Use only a dynamic tracer. |
pattern TraceString :: String -> TraceValue | Use only string tracing. |
pattern DontTrace :: TraceValue | Do not trace the value. |
class MonadInspectSTM m => MonadTraceSTM (m :: Type -> Type) where #
MonadTraceSTM
allows to trace values of stm variables when stm
transaction is committed. This allows to verify invariants when a variable
is committed.
traceTSem :: proxy m -> TSem m -> (Maybe Integer -> Integer -> InspectMonad m TraceValue) -> STM m () #
traceTSemIO :: TSem m -> (Maybe Integer -> Integer -> InspectMonad m TraceValue) -> m () #
Instances
data StrictTArray m i e Source #
Instances
(MArray (TArray m) e stm, Monad stm) => MArray (StrictTArray m) e stm Source # | |
Defined in Control.Concurrent.Class.MonadSTM.Strict.TArray getBounds :: Ix i => StrictTArray m i e -> stm (i, i) # getNumElements :: Ix i => StrictTArray m i e -> stm Int newArray :: Ix i => (i, i) -> e -> stm (StrictTArray m i e) # newArray_ :: Ix i => (i, i) -> stm (StrictTArray m i e) # unsafeNewArray_ :: Ix i => (i, i) -> stm (StrictTArray m i e) unsafeRead :: Ix i => StrictTArray m i e -> Int -> stm e unsafeWrite :: Ix i => StrictTArray m i e -> Int -> e -> stm () |
type LazyTArray m = TArray m Source #
fromLazyTArray :: LazyTArray m i e -> StrictTArray m i e Source #
data StrictTBQueue m a Source #
type LazyTBQueue m = TBQueue m Source #
fromLazyTBQueue :: LazyTBQueue m a -> StrictTBQueue m a Source #
castStrictTBQueue :: LazyTBQueue m ~ LazyTBQueue n => StrictTBQueue m a -> StrictTBQueue n a Source #
labelTBQueue :: MonadLabelledSTM m => StrictTBQueue m a -> String -> STM m () Source #
labelTBQueueIO :: MonadLabelledSTM m => StrictTBQueue m a -> String -> m () Source #
traceTBQueue :: MonadTraceSTM m => proxy m -> StrictTBQueue m a -> (Maybe [a] -> [a] -> InspectMonad m TraceValue) -> STM m () Source #
traceTBQueueIO :: MonadTraceSTM m => StrictTBQueue m a -> (Maybe [a] -> [a] -> InspectMonad m TraceValue) -> m () Source #
newTBQueue :: MonadSTM m => Natural -> STM m (StrictTBQueue m a) Source #
newTBQueueIO :: MonadSTM m => Natural -> m (StrictTBQueue m a) Source #
readTBQueue :: MonadSTM m => StrictTBQueue m a -> STM m a Source #
tryReadTBQueue :: MonadSTM m => StrictTBQueue m a -> STM m (Maybe a) Source #
peekTBQueue :: MonadSTM m => StrictTBQueue m a -> STM m a Source #
tryPeekTBQueue :: MonadSTM m => StrictTBQueue m a -> STM m (Maybe a) Source #
flushTBQueue :: MonadSTM m => StrictTBQueue m a -> STM m [a] Source #
writeTBQueue :: MonadSTM m => StrictTBQueue m a -> a -> STM m () Source #
lengthTBQueue :: MonadSTM m => StrictTBQueue m a -> STM m Natural Source #
isEmptyTBQueue :: MonadSTM m => StrictTBQueue m a -> STM m Bool Source #
isFullTBQueue :: MonadSTM m => StrictTBQueue m a -> STM m Bool Source #
unGetTBQueue :: MonadSTM m => StrictTBQueue m a -> a -> STM m () Source #
data StrictTChan m a Source #
fromLazyTChan :: LazyTChan m a -> StrictTChan m a Source #
castStrictTChan :: LazyTChan m ~ LazyTChan n => StrictTChan m a -> StrictTChan n a Source #
newBroadcastTChan :: MonadSTM m => STM m (StrictTChan m a) Source #
writeTChan :: MonadSTM m => StrictTChan m a -> a -> STM m () Source #
tryReadTChan :: MonadSTM m => StrictTChan m a -> STM m (Maybe a) Source #
tryPeekTChan :: MonadSTM m => StrictTChan m a -> STM m (Maybe a) Source #
dupTChan :: MonadSTM m => StrictTChan m a -> STM m (StrictTChan m a) Source #
unGetTChan :: MonadSTM m => StrictTChan m a -> a -> STM m () Source #
isEmptyTChan :: MonadSTM m => StrictTChan m a -> STM m Bool Source #
cloneTChan :: MonadSTM m => StrictTChan m a -> STM m (StrictTChan m a) Source #
data StrictTMVar m a Source #
TMVar
that keeps its value in WHNF at all times
Does not support an invariant: if the invariant would not be satisfied, we would not be able to put a value into an empty TMVar, which would lead to very hard to debug bugs where code is blocked indefinitely.
fromLazyTMVar :: LazyTMVar m a -> StrictTMVar m a Source #
labelTMVar :: MonadLabelledSTM m => StrictTMVar m a -> String -> STM m () Source #
labelTMVarIO :: MonadLabelledSTM m => StrictTMVar m a -> String -> m () Source #
traceTMVar :: MonadTraceSTM m => proxy m -> StrictTMVar m a -> (Maybe (Maybe a) -> Maybe a -> InspectMonad m TraceValue) -> STM m () Source #
traceTMVarIO :: MonadTraceSTM m => StrictTMVar m a -> (Maybe (Maybe a) -> Maybe a -> InspectMonad m TraceValue) -> m () Source #
castStrictTMVar :: LazyTMVar m ~ LazyTMVar n => StrictTMVar m a -> StrictTMVar n a Source #
newTMVarIO :: MonadSTM m => a -> m (StrictTMVar m a) Source #
newEmptyTMVar :: MonadSTM m => STM m (StrictTMVar m a) Source #
newEmptyTMVarIO :: MonadSTM m => m (StrictTMVar m a) Source #
tryTakeTMVar :: MonadSTM m => StrictTMVar m a -> STM m (Maybe a) Source #
tryPutTMVar :: MonadSTM m => StrictTMVar m a -> a -> STM m Bool Source #
tryReadTMVar :: MonadSTM m => StrictTMVar m a -> STM m (Maybe a) Source #
isEmptyTMVar :: MonadSTM m => StrictTMVar m a -> STM m Bool Source #
data StrictTQueue m a Source #
type LazyTQueue m = TQueue m Source #
fromLazyTQueue :: LazyTQueue m a -> StrictTQueue m a Source #
castStrictTQueue :: LazyTQueue m ~ LazyTQueue n => StrictTQueue m a -> StrictTQueue n a Source #
labelTQueue :: MonadLabelledSTM m => StrictTQueue m a -> String -> STM m () Source #
labelTQueueIO :: MonadLabelledSTM m => StrictTQueue m a -> String -> m () Source #
traceTQueue :: MonadTraceSTM m => proxy m -> StrictTQueue m a -> (Maybe [a] -> [a] -> InspectMonad m TraceValue) -> STM m () Source #
traceTQueueIO :: MonadTraceSTM m => StrictTQueue m a -> (Maybe [a] -> [a] -> InspectMonad m TraceValue) -> m () Source #
newTQueueIO :: MonadSTM m => m (StrictTQueue m a) Source #
readTQueue :: MonadSTM m => StrictTQueue m a -> STM m a Source #
tryReadTQueue :: MonadSTM m => StrictTQueue m a -> STM m (Maybe a) Source #
peekTQueue :: MonadSTM m => StrictTQueue m a -> STM m a Source #
tryPeekTQueue :: MonadSTM m => StrictTQueue m a -> STM m (Maybe a) Source #
flushTQueue :: MonadSTM m => StrictTQueue m a -> STM m [a] Source #
writeTQueue :: MonadSTM m => StrictTQueue m a -> a -> STM m () Source #
isEmptyTQueue :: MonadSTM m => StrictTQueue m a -> STM m Bool Source #
unGetTQueue :: MonadSTM m => StrictTQueue m a -> a -> STM m () Source #
data StrictTVar m a Source #
labelTVar :: MonadLabelledSTM m => StrictTVar m a -> String -> STM m () Source #
labelTVarIO :: MonadLabelledSTM m => StrictTVar m a -> String -> m () Source #
traceTVar :: MonadTraceSTM m => proxy m -> StrictTVar m a -> (Maybe a -> a -> InspectMonad m TraceValue) -> STM m () Source #
traceTVarIO :: MonadTraceSTM m => StrictTVar m a -> (Maybe a -> a -> InspectMonad m TraceValue) -> m () Source #
castStrictTVar :: LazyTVar m ~ LazyTVar n => StrictTVar m a -> StrictTVar n a Source #
toLazyTVar :: StrictTVar m a -> LazyTVar m a Source #
Get the underlying TVar
Since we obviously cannot guarantee that updates to this LazyTVar
will be
strict, this should be used with caution.
fromLazyTVar :: LazyTVar m a -> StrictTVar m a Source #
newTVarIO :: MonadSTM m => a -> m (StrictTVar m a) Source #
:: (MonadSTM m, HasCallStack) | |
=> (a -> Maybe String) | Invariant (expect |
-> a | |
-> STM m (StrictTVar m a) |
newTVarWithInvariantIO Source #
:: (MonadSTM m, HasCallStack) | |
=> (a -> Maybe String) | Invariant (expect |
-> a | |
-> m (StrictTVar m a) |
readTVarIO :: MonadSTM m => StrictTVar m a -> m a Source #
writeTVar :: (MonadSTM m, HasCallStack) => StrictTVar m a -> a -> STM m () Source #
modifyTVar :: MonadSTM m => StrictTVar m a -> (a -> a) -> STM m () Source #
checkInvariant :: HasCallStack => Maybe String -> a -> a Source #
Check invariant (if enabled) before continuing
checkInvariant mErr x
is equal to x
if mErr == Nothing
, and throws
an error err
if mErr == Just err
.
This is exported so that other code that wants to conditionally check invariants can reuse the same logic, rather than having to introduce new per-package flags.