| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Ouroboros.Consensus.Util.MonadSTM.StrictMVar
Synopsis
- data StrictMVar m a = StrictMVar {}
- castStrictMVar :: (TMVar m ~ TMVar n, TVar m ~ TVar n) => StrictMVar m a -> StrictMVar n a
- newMVar :: MonadSTM m => a -> m (StrictMVar m a)
- newMVarWithInvariant :: (MonadSTM m, HasCallStack) => (a -> Maybe String) -> a -> m (StrictMVar m a)
- newEmptyMVar :: MonadSTM m => a -> m (StrictMVar m a)
- newEmptyMVarWithInvariant :: MonadSTM m => (a -> Maybe String) -> a -> m (StrictMVar m a)
- takeMVar :: MonadSTM m => StrictMVar m a -> m a
- tryTakeMVar :: MonadSTM m => StrictMVar m a -> m (Maybe a)
- putMVar :: (MonadSTM m, HasCallStack) => StrictMVar m a -> a -> m ()
- tryPutMVar :: (MonadSTM m, HasCallStack) => StrictMVar m a -> a -> m Bool
- readMVar :: MonadSTM m => StrictMVar m a -> m a
- readMVarSTM :: MonadSTM m => StrictMVar m a -> STM m a
- tryReadMVar :: MonadSTM m => StrictMVar m a -> m (Maybe a)
- swapMVar :: (MonadSTM m, HasCallStack) => StrictMVar m a -> a -> m a
- isEmptyMVar :: MonadSTM m => StrictMVar m a -> m Bool
- updateMVar :: (MonadSTM m, HasCallStack) => StrictMVar m a -> (a -> (a, b)) -> m b
- updateMVar_ :: (MonadSTM m, HasCallStack) => StrictMVar m a -> (a -> a) -> m ()
- modifyMVar :: (MonadSTM m, MonadCatch m, HasCallStack) => StrictMVar m a -> (a -> m (a, b)) -> m b
- modifyMVar_ :: (MonadSTM m, MonadCatch m, HasCallStack) => StrictMVar m a -> (a -> m a) -> m ()
Documentation
data StrictMVar m a Source #
Strict MVar (modelled using a lazy TMVar under the hood)
The StrictMVar API is slightly stronger than the usual MVar one, as we
offer a primitive to read the value of the MVar even if it is empty (in which
case we will return the oldest known stale one). See readMVarSTM.
There is a weaker invariant for a StrictMVar than for a StrictTVar:
although all functions that modify the StrictMVar check the invariant, we
do not guarantee that the value inside the StrictMVar always satisfies
the invariant. Instead, we do guarantee that if the StrictMVar 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 MVar 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 StrictMVar.
Constructors
| StrictMVar | |
Fields
| |
castStrictMVar :: (TMVar m ~ TMVar n, TVar m ~ TVar n) => StrictMVar m a -> StrictMVar n a Source #
newMVar :: MonadSTM m => a -> m (StrictMVar m a) Source #
Arguments
| :: (MonadSTM m, HasCallStack) | |
| => (a -> Maybe String) | Invariant (expect |
| -> a | |
| -> m (StrictMVar m a) |
newEmptyMVar :: MonadSTM m => a -> m (StrictMVar m a) Source #
newEmptyMVarWithInvariant Source #
Arguments
| :: MonadSTM m | |
| => (a -> Maybe String) | Invariant (expect |
| -> a | The initial stale value |
| -> m (StrictMVar m a) |
Create an initially empty StrictMVar
NOTE: Since readMVarSTM allows to read the StrictMVar even when it is
empty, we need an initial value of a even though the StrictMVar starts
out empty. However, we are NOT strict in this value, to allow it to be
error.
takeMVar :: MonadSTM m => StrictMVar m a -> m a Source #
tryTakeMVar :: MonadSTM m => StrictMVar m a -> m (Maybe a) Source #
putMVar :: (MonadSTM m, HasCallStack) => StrictMVar m a -> a -> m () Source #
tryPutMVar :: (MonadSTM m, HasCallStack) => StrictMVar m a -> a -> m Bool Source #
readMVar :: MonadSTM m => StrictMVar m a -> m a Source #
readMVarSTM :: MonadSTM m => StrictMVar m a -> STM m a Source #
Read the possibly-stale value of the MVar
Will return the current value of the MVar if it non-empty, or the last
known value otherwise.
tryReadMVar :: MonadSTM m => StrictMVar m a -> m (Maybe a) Source #
swapMVar :: (MonadSTM m, HasCallStack) => StrictMVar m a -> a -> m a Source #
Swap value of a StrictMVar
NOTE: Since swapping the value can't leave the StrictMVar 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
putMVar, otherwise it will be difficult to understand when a StrictMVar
is updated and when it is not.
isEmptyMVar :: MonadSTM m => StrictMVar m a -> m Bool Source #
updateMVar :: (MonadSTM m, HasCallStack) => StrictMVar m a -> (a -> (a, b)) -> m b Source #
updateMVar_ :: (MonadSTM m, HasCallStack) => StrictMVar m a -> (a -> a) -> m () Source #
modifyMVar :: (MonadSTM m, MonadCatch m, HasCallStack) => StrictMVar m a -> (a -> m (a, b)) -> m b Source #
modifyMVar_ :: (MonadSTM m, MonadCatch m, HasCallStack) => StrictMVar m a -> (a -> m a) -> m () Source #