Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Synopsis
- module Control.Concurrent.Class.MonadSTM.TQueue
- module Control.Concurrent.Class.MonadSTM.TBQueue
- data StrictSVar m a = StrictSVar {}
- castStrictSVar ∷ (TMVar m ~ TMVar n, TVar m ~ TVar n) ⇒ StrictSVar m a → StrictSVar n a
- isEmptySVar ∷ MonadSTM m ⇒ StrictSVar m a → m Bool
- modifySVar ∷ (MonadSTM m, MonadCatch m, HasCallStack) ⇒ StrictSVar m a → (a → m (a, b)) → m b
- modifySVar_ ∷ (MonadSTM m, MonadCatch m, HasCallStack) ⇒ StrictSVar m a → (a → m a) → m ()
- putSVar ∷ (MonadSTM m, HasCallStack) ⇒ StrictSVar m a → a → m ()
- readSVar ∷ MonadSTM m ⇒ StrictSVar m a → m a
- readSVarSTM ∷ MonadSTM m ⇒ StrictSVar m a → STM m a
- swapSVar ∷ (MonadSTM m, HasCallStack) ⇒ StrictSVar m a → a → m a
- takeSVar ∷ MonadSTM m ⇒ StrictSVar m a → m a
- tryPutSVar ∷ (MonadSTM m, HasCallStack) ⇒ StrictSVar m a → a → m Bool
- tryReadSVar ∷ MonadSTM m ⇒ StrictSVar m a → m (Maybe a)
- tryTakeSVar ∷ MonadSTM m ⇒ StrictSVar m a → m (Maybe a)
- updateSVar ∷ (MonadSTM m, HasCallStack) ⇒ StrictSVar m a → (a → (a, b)) → m b
- updateSVar_ ∷ (MonadSTM m, HasCallStack) ⇒ StrictSVar m a → (a → a) → m ()
- class (Monad m, Monad (STM m)) ⇒ MonadSTM (m ∷ Type → Type) where
- type family STM (m ∷ Type → Type) = (stm ∷ Type → Type) | stm → m
- class MonadInspectSTM m ⇒ MonadTraceSTM (m ∷ Type → Type) where
- traceTMVar ∷ proxy m → TMVar m a → (Maybe (Maybe a) → Maybe a → InspectMonad m TraceValue) → STM m ()
- traceTQueue ∷ proxy m → TQueue m a → (Maybe [a] → [a] → InspectMonad m TraceValue) → STM m ()
- traceTBQueue ∷ proxy m → TBQueue m a → (Maybe [a] → [a] → InspectMonad m TraceValue) → STM m ()
- traceTSem ∷ proxy m → TSem m → (Maybe Integer → Integer → InspectMonad m TraceValue) → STM m ()
- traceTMVarIO ∷ TMVar m a → (Maybe (Maybe a) → Maybe a → InspectMonad m TraceValue) → m ()
- traceTQueueIO ∷ TQueue m a → (Maybe [a] → [a] → InspectMonad m TraceValue) → m ()
- traceTBQueueIO ∷ TBQueue m a → (Maybe [a] → [a] → InspectMonad m TraceValue) → m ()
- traceTSemIO ∷ TSem m → (Maybe Integer → Integer → InspectMonad m TraceValue) → m ()
- data TraceValue where
- TraceValue ∷ ∀ tr. Typeable tr ⇒ {..} → TraceValue
- pattern DontTrace ∷ TraceValue
- pattern TraceString ∷ String → TraceValue
- pattern TraceDynamic ∷ () ⇒ Typeable tr ⇒ tr → TraceValue
- 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)
- type family InspectMonad (m ∷ Type → Type) ∷ Type → Type
- class MonadSTM m ⇒ MonadLabelledSTM (m ∷ Type → Type)
- data StrictTMVar (m ∷ Type → Type) a
- type LazyTMVar (m ∷ Type → Type) = TMVar m
- throwSTM ∷ ∀ (m ∷ Type → Type) e a. (MonadSTM m, MonadThrow (STM m), Exception e) ⇒ e → STM m a
- labelTMVar ∷ ∀ (m ∷ Type → Type) a. MonadLabelledSTM m ⇒ StrictTMVar m a → String → STM m ()
- labelTMVarIO ∷ MonadLabelledSTM m ⇒ StrictTMVar m a → String → m ()
- newEmptyTMVar ∷ ∀ (m ∷ Type → Type) a. MonadSTM m ⇒ STM m (StrictTMVar m a)
- takeTMVar ∷ ∀ (m ∷ Type → Type) a. MonadSTM m ⇒ StrictTMVar m a → STM m a
- tryTakeTMVar ∷ ∀ (m ∷ Type → Type) a. MonadSTM m ⇒ StrictTMVar m a → STM m (Maybe a)
- putTMVar ∷ ∀ (m ∷ Type → Type) a. MonadSTM m ⇒ StrictTMVar m a → a → STM m ()
- tryPutTMVar ∷ ∀ (m ∷ Type → Type) a. MonadSTM m ⇒ StrictTMVar m a → a → STM m Bool
- readTMVar ∷ ∀ (m ∷ Type → Type) a. MonadSTM m ⇒ StrictTMVar m a → STM m a
- tryReadTMVar ∷ ∀ (m ∷ Type → Type) a. MonadSTM m ⇒ StrictTMVar m a → STM m (Maybe a)
- swapTMVar ∷ ∀ (m ∷ Type → Type) a. MonadSTM m ⇒ StrictTMVar m a → a → STM m a
- writeTMVar ∷ ∀ (m ∷ Type → Type) a. MonadSTM m ⇒ StrictTMVar m a → a → STM m ()
- isEmptyTMVar ∷ ∀ (m ∷ Type → Type) a. MonadSTM m ⇒ StrictTMVar m a → STM m Bool
- newEmptyTMVarIO ∷ MonadSTM m ⇒ m (StrictTMVar m a)
- fromLazyTMVar ∷ ∀ (m ∷ Type → Type) a. LazyTMVar m a → StrictTMVar m a
- castStrictTMVar ∷ ∀ (m ∷ Type → Type) (n ∷ Type → Type) a. LazyTMVar m ~ LazyTMVar n ⇒ StrictTMVar m a → StrictTMVar n a
- newEmptySVar ∷ (MonadSTM m, NoThunks a) ⇒ a → m (StrictSVar m a)
- newSVar ∷ (MonadSTM m, HasCallStack, NoThunks a) ⇒ a → m (StrictSVar m a)
- uncheckedNewEmptySVar ∷ MonadSTM m ⇒ a → m (StrictSVar m a)
- uncheckedNewSVar ∷ MonadSTM m ⇒ a → m (StrictSVar m a)
Documentation
data StrictSVar m a Source #
Strict SVar (modelled using a lazy TMVar
under the hood)
The StrictSVar
API is slightly stronger than the usual SVar
one, as we
offer a primitive to read the value of the SVar even if it is empty (in which
case we will return the oldest known stale one). See readSVarSTM
.
There is a weaker invariant for a StrictSVar
than for a StrictTVar
:
although all functions that modify the StrictSVar
check the invariant, we
do not guarantee that the value inside the StrictSVar
always satisfies
the invariant. Instead, we do guarantee that if the StrictSVar
is updated
with a value that does not satisfy the invariant, an exception is thrown. The
reason for this weaker guarantee is that leaving an SVar
empty can lead to
very hard to debug "blocked indefinitely" problems.
This is also the reason we do not offer support for an invariant in
StrictTMVar
: if we throw an exception from an STM transaction, the STM
transaction is not executed, and so we would not even be able to provide the
weaker guarantee that we provide for StrictSVar
.
StrictSVar | |
|
Instances
NoThunks a ⇒ NoThunks (StrictSVar IO a) Source # | |
NoThunks (StrictSVar m a) ⇒ NoThunks (StrictSVar (WithEarlyExit m) a) Source # | |
Defined in Ouroboros.Consensus.Util.EarlyExit noThunks ∷ Context → StrictSVar (WithEarlyExit m) a → IO (Maybe ThunkInfo) Source # wNoThunks ∷ Context → StrictSVar (WithEarlyExit m) a → IO (Maybe ThunkInfo) Source # showTypeOf ∷ Proxy (StrictSVar (WithEarlyExit m) a) → String Source # |
castStrictSVar ∷ (TMVar m ~ TMVar n, TVar m ~ TVar n) ⇒ StrictSVar m a → StrictSVar n a Source #
isEmptySVar ∷ MonadSTM m ⇒ StrictSVar m a → m Bool Source #
modifySVar ∷ (MonadSTM m, MonadCatch m, HasCallStack) ⇒ StrictSVar m a → (a → m (a, b)) → m b Source #
modifySVar_ ∷ (MonadSTM m, MonadCatch m, HasCallStack) ⇒ StrictSVar m a → (a → m a) → m () Source #
putSVar ∷ (MonadSTM m, HasCallStack) ⇒ StrictSVar m a → a → m () Source #
readSVar ∷ MonadSTM m ⇒ StrictSVar m a → m a Source #
readSVarSTM ∷ MonadSTM m ⇒ StrictSVar m a → STM m a Source #
Read the possibly-stale value of the SVar
Will return the current value of the SVar
if it non-empty, or the last
known value otherwise.
swapSVar ∷ (MonadSTM m, HasCallStack) ⇒ StrictSVar m a → a → m a Source #
Swap value of a StrictSVar
NOTE: Since swapping the value can't leave the StrictSVar
empty, we
could check the invariant first and only then swap. We nonetheless swap
first and check the invariant after to keep the semantics the same with
putSVar
, otherwise it will be difficult to understand when a StrictSVar
is updated and when it is not.
takeSVar ∷ MonadSTM m ⇒ StrictSVar m a → m a Source #
tryPutSVar ∷ (MonadSTM m, HasCallStack) ⇒ StrictSVar m a → a → m Bool Source #
tryReadSVar ∷ MonadSTM m ⇒ StrictSVar m a → m (Maybe a) Source #
tryTakeSVar ∷ MonadSTM m ⇒ StrictSVar m a → m (Maybe a) Source #
updateSVar ∷ (MonadSTM m, HasCallStack) ⇒ StrictSVar m a → (a → (a, b)) → m b Source #
updateSVar_ ∷ (MonadSTM m, HasCallStack) ⇒ StrictSVar m a → (a → a) → m () Source #
class (Monad m, Monad (STM m)) ⇒ MonadSTM (m ∷ Type → Type) where Source #
The STM primitives parametrised by a monad m
.
atomically, newTVar, readTVar, writeTVar, retry, orElse, newTMVar, newEmptyTMVar, takeTMVar, tryTakeTMVar, putTMVar, tryPutTMVar, readTMVar, tryReadTMVar, swapTMVar, writeTMVar, 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 Source #
Atomically run an STM computation.
See atomically
.
See retry
.
orElse ∷ STM m a → STM m a → STM m a Source #
See orElse
.
check ∷ Bool → STM m () Source #
See check
.
Instances
type family STM (m ∷ Type → Type) = (stm ∷ Type → Type) | stm → m Source #
The STM monad.
Instances
type STM IO | |
Defined in Control.Monad.Class.MonadSTM.Internal | |
type STM (WithEarlyExit m) Source # | |
Defined in Ouroboros.Consensus.Util.EarlyExit | |
type STM (ReaderT r m) | |
Defined in Control.Monad.Class.MonadSTM.Internal |
class MonadInspectSTM m ⇒ MonadTraceSTM (m ∷ Type → Type) where Source #
MonadTraceSTM
allows to trace values of stm variables when stm
transaction is committed. This allows to verify invariants when a variable
is committed.
traceTMVar ∷ proxy m → TMVar m a → (Maybe (Maybe a) → Maybe a → InspectMonad m TraceValue) → STM m () Source #
traceTQueue ∷ proxy m → TQueue m a → (Maybe [a] → [a] → InspectMonad m TraceValue) → STM m () Source #
traceTBQueue ∷ proxy m → TBQueue m a → (Maybe [a] → [a] → InspectMonad m TraceValue) → STM m () Source #
traceTSem ∷ proxy m → TSem m → (Maybe Integer → Integer → InspectMonad m TraceValue) → STM m () Source #
traceTMVarIO ∷ TMVar m a → (Maybe (Maybe a) → Maybe a → InspectMonad m TraceValue) → m () Source #
traceTQueueIO ∷ TQueue m a → (Maybe [a] → [a] → InspectMonad m TraceValue) → m () Source #
traceTBQueueIO ∷ TBQueue m a → (Maybe [a] → [a] → InspectMonad m TraceValue) → m () Source #
traceTSemIO ∷ TSem m → (Maybe Integer → Integer → InspectMonad m TraceValue) → m () Source #
Instances
data TraceValue where Source #
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 DontTrace ∷ TraceValue | Do not trace the value. |
pattern TraceString ∷ String → TraceValue | Use only string tracing. |
pattern TraceDynamic ∷ () ⇒ Typeable tr ⇒ tr → TraceValue | Use only a dynamic tracer. |
class (MonadSTM m, Monad (InspectMonad m)) ⇒ MonadInspectSTM (m ∷ Type → Type) where Source #
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 Source #
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) Source #
Return the value of a MonadSTM
as an InspectMonad
computation.
Instances
MonadInspectSTM IO | |
Defined in Control.Monad.Class.MonadSTM.Internal inspectTVar ∷ proxy IO → TVar IO a → InspectMonad IO a Source # inspectTMVar ∷ proxy IO → TMVar IO a → InspectMonad IO (Maybe a) Source # | |
(MonadInspectSTM m, Monad (InspectMonad m)) ⇒ MonadInspectSTM (WithEarlyExit m) Source # | |
Defined in Ouroboros.Consensus.Util.EarlyExit type InspectMonad (WithEarlyExit m) ∷ Type → Type Source # inspectTVar ∷ proxy (WithEarlyExit m) → TVar (WithEarlyExit m) a → InspectMonad (WithEarlyExit m) a Source # inspectTMVar ∷ proxy (WithEarlyExit m) → TMVar (WithEarlyExit m) a → InspectMonad (WithEarlyExit m) (Maybe a) Source # |
type family InspectMonad (m ∷ Type → Type) ∷ Type → Type Source #
Instances
type InspectMonad IO | |
Defined in Control.Monad.Class.MonadSTM.Internal | |
type InspectMonad (WithEarlyExit m) Source # | |
Defined in Ouroboros.Consensus.Util.EarlyExit |
class MonadSTM m ⇒ MonadLabelledSTM (m ∷ Type → Type) Source #
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
data StrictTMVar (m ∷ Type → Type) a Source #
TMVar
that keeps its value in WHNF at all times
throwSTM ∷ ∀ (m ∷ Type → Type) e a. (MonadSTM m, MonadThrow (STM m), Exception e) ⇒ e → STM m a Source #
throwIO
specialised to stm
monad.
labelTMVar ∷ ∀ (m ∷ Type → Type) a. MonadLabelledSTM m ⇒ StrictTMVar m a → String → STM m () Source #
labelTMVarIO ∷ MonadLabelledSTM m ⇒ StrictTMVar m a → String → m () Source #
newEmptyTMVar ∷ ∀ (m ∷ Type → Type) a. MonadSTM m ⇒ STM m (StrictTMVar m a) Source #
tryTakeTMVar ∷ ∀ (m ∷ Type → Type) a. MonadSTM m ⇒ StrictTMVar m a → STM m (Maybe a) Source #
tryPutTMVar ∷ ∀ (m ∷ Type → Type) a. MonadSTM m ⇒ StrictTMVar m a → a → STM m Bool Source #
tryReadTMVar ∷ ∀ (m ∷ Type → Type) a. MonadSTM m ⇒ StrictTMVar m a → STM m (Maybe a) Source #
writeTMVar ∷ ∀ (m ∷ Type → Type) a. MonadSTM m ⇒ StrictTMVar m a → a → STM m () Source #
isEmptyTMVar ∷ ∀ (m ∷ Type → Type) a. MonadSTM m ⇒ StrictTMVar m a → STM m Bool Source #
newEmptyTMVarIO ∷ MonadSTM m ⇒ m (StrictTMVar m a) Source #
fromLazyTMVar ∷ ∀ (m ∷ Type → Type) a. LazyTMVar m a → StrictTMVar m a Source #
castStrictTMVar ∷ ∀ (m ∷ Type → Type) (n ∷ Type → Type) a. LazyTMVar m ~ LazyTMVar n ⇒ StrictTMVar m a → StrictTMVar n a Source #
newEmptySVar ∷ (MonadSTM m, NoThunks a) ⇒ a → m (StrictSVar m a) Source #
newSVar ∷ (MonadSTM m, HasCallStack, NoThunks a) ⇒ a → m (StrictSVar m a) Source #
Temporary
uncheckedNewEmptySVar ∷ MonadSTM m ⇒ a → m (StrictSVar m a) Source #
uncheckedNewSVar ∷ MonadSTM m ⇒ a → m (StrictSVar m a) Source #