ouroboros-consensus-0.21.0.0: Consensus layer for the Ouroboros blockchain protocol
Safe HaskellSafe-Inferred
LanguageHaskell2010

Ouroboros.Consensus.Util.NormalForm.StrictMVar

Description

StrictMVars with NoThunks invariants.

Custom invariants can still be specified in addition to the default NoThunks invariant. See newMVarWithInvariant and newEmptyMVarWithInvariant.

Use the checkmvarinvariants cabal flag from the strict-checked-vars package to enable or disable invariant checks at compile time.

The exports of this module (should) mirror the exports of the Control.Concurrent.Class.MonadMVar.Strict.Checked module from the strict-checked-vars package.

Synopsis

StrictMVar

newEmptyMVar ∷ (MonadMVar m, NoThunks a) ⇒ m (StrictMVar m a) Source #

Create an empty StrictMVar with a NoThunks invariant.

newEmptyMVarWithInvariant ∷ (MonadMVar m, NoThunks a) ⇒ (a → Maybe String) → m (StrictMVar m a) Source #

Create an empty StrictMVar with a custom invariant and a NoThunks invariant.

When both the custom and NoThunks invariants are broken, only the error related to the custom invariant is reported.

newMVar ∷ (HasCallStack, MonadMVar m, NoThunks a) ⇒ a → m (StrictMVar m a) Source #

Create a StrictMVar with a NoThunks invariant.

newMVarWithInvariant ∷ (HasCallStack, MonadMVar m, NoThunks a) ⇒ (a → Maybe String) → a → m (StrictMVar m a) Source #

Create a StrictMVar with a custom invariant and a NoThunks invariant.

When both the custom and NoThunks invariants are broken, only the error related to the custom invariant is reported.

Invariant

Unchecked

uncheckedNewEmptyMVarMonadMVar m ⇒ m (StrictMVar m a) Source #

Like newEmptyMVar, but without a NoThunks invariant.

uncheckedNewMVarMonadMVar m ⇒ a → m (StrictMVar m a) Source #

Like newMVar, but without a NoThunks invariant.

Re-exports

class Monad m ⇒ MonadMVar (m ∷ TypeType) Source #

Instances

Instances details
MonadMVar IO 
Instance details

Defined in Control.Concurrent.Class.MonadMVar

Associated Types

type MVar IOTypeType Source #

Methods

newEmptyMVarIO (MVar IO a) Source #

takeMVarMVar IO a → IO a Source #

putMVarMVar IO a → a → IO () Source #

tryTakeMVarMVar IO a → IO (Maybe a) Source #

tryPutMVarMVar IO a → a → IO Bool Source #

isEmptyMVarMVar IO a → IO Bool Source #

newMVar ∷ a → IO (MVar IO a) Source #

readMVarMVar IO a → IO a Source #

tryReadMVarMVar IO a → IO (Maybe a) Source #

swapMVarMVar IO a → a → IO a Source #

withMVarMVar IO a → (a → IO b) → IO b Source #

withMVarMaskedMVar IO a → (a → IO b) → IO b Source #

modifyMVar_MVar IO a → (a → IO a) → IO () Source #

modifyMVarMVar IO a → (a → IO (a, b)) → IO b Source #

modifyMVarMasked_MVar IO a → (a → IO a) → IO () Source #

modifyMVarMaskedMVar IO a → (a → IO (a, b)) → IO b Source #

(MonadMVar m, MonadMask m, MonadEvaluate m) ⇒ MonadMVar (WithEarlyExit m) Source # 
Instance details

Defined in Ouroboros.Consensus.Util.EarlyExit

Associated Types

type MVar (WithEarlyExit m) ∷ TypeType Source #

(MonadMask m, MonadMVar m) ⇒ MonadMVar (ReaderT r m) 
Instance details

Defined in Control.Concurrent.Class.MonadMVar

Associated Types

type MVar (ReaderT r m) ∷ TypeType Source #

Methods

newEmptyMVarReaderT r m (MVar (ReaderT r m) a) Source #

takeMVarMVar (ReaderT r m) a → ReaderT r m a Source #

putMVarMVar (ReaderT r m) a → a → ReaderT r m () Source #

tryTakeMVarMVar (ReaderT r m) a → ReaderT r m (Maybe a) Source #

tryPutMVarMVar (ReaderT r m) a → a → ReaderT r m Bool Source #

isEmptyMVarMVar (ReaderT r m) a → ReaderT r m Bool Source #

newMVar ∷ a → ReaderT r m (MVar (ReaderT r m) a) Source #

readMVarMVar (ReaderT r m) a → ReaderT r m a Source #

tryReadMVarMVar (ReaderT r m) a → ReaderT r m (Maybe a) Source #

swapMVarMVar (ReaderT r m) a → a → ReaderT r m a Source #

withMVarMVar (ReaderT r m) a → (a → ReaderT r m b) → ReaderT r m b Source #

withMVarMaskedMVar (ReaderT r m) a → (a → ReaderT r m b) → ReaderT r m b Source #

modifyMVar_MVar (ReaderT r m) a → (a → ReaderT r m a) → ReaderT r m () Source #

modifyMVarMVar (ReaderT r m) a → (a → ReaderT r m (a, b)) → ReaderT r m b Source #

modifyMVarMasked_MVar (ReaderT r m) a → (a → ReaderT r m a) → ReaderT r m () Source #

modifyMVarMaskedMVar (ReaderT r m) a → (a → ReaderT r m (a, b)) → ReaderT r m b Source #

type LazyMVar (m ∷ TypeType) = MVar m Source #

data StrictMVar (m ∷ TypeType) a Source #

A strict MVar with invariant checking.

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.

checkInvariantHasCallStackMaybe 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.

takeMVarMonadMVar m ⇒ StrictMVar m a → m a Source #

readMVarMonadMVar m ⇒ StrictMVar m a → m a Source #

putMVar ∷ (HasCallStack, MonadMVar m) ⇒ StrictMVar m a → a → m () Source #

tryTakeMVarMonadMVar m ⇒ StrictMVar m a → m (Maybe a) Source #

tryPutMVar ∷ (HasCallStack, MonadMVar m) ⇒ StrictMVar m a → a → m Bool Source #

tryReadMVarMonadMVar m ⇒ StrictMVar m a → m (Maybe a) Source #

withMVarMonadMVar m ⇒ StrictMVar m a → (a → m b) → m b Source #

modifyMVar_ ∷ (HasCallStack, MonadMVar m) ⇒ StrictMVar m a → (a → m a) → m () Source #

modifyMVar_ is defined in terms of modifyMVar.

swapMVar ∷ (HasCallStack, MonadMVar m) ⇒ StrictMVar m a → a → m a Source #

withMVarMaskedMonadMVar m ⇒ StrictMVar m a → (a → m b) → m b Source #

modifyMVar ∷ (HasCallStack, MonadMVar m) ⇒ StrictMVar m a → (a → m (a, b)) → m b Source #

modifyMVarMasked_ ∷ (HasCallStack, MonadMVar m) ⇒ StrictMVar m a → (a → m a) → m () Source #

modifyMVarMasked_ is defined in terms of modifyMVarMasked.

modifyMVarMasked ∷ (HasCallStack, MonadMVar m) ⇒ StrictMVar m a → (a → m (a, b)) → m b Source #

castStrictMVar ∷ ∀ (m ∷ TypeType) (n ∷ TypeType) a. LazyMVar m ~ LazyMVar n ⇒ StrictMVar m a → StrictMVar n a Source #

toLazyMVar ∷ ∀ (m ∷ TypeType) a. StrictMVar m a → LazyMVar m a Source #

Get the underlying MVar

Since we obviously can not guarantee that updates to this LazyMVar will be strict, this should be used with caution.

Similarly, we can not guarantee that updates to this LazyMVar do not break the original invariant that the StrictMVar held.

fromLazyMVar ∷ ∀ (m ∷ TypeType) a. LazyMVar m a → StrictMVar m a Source #

Create a StrictMVar from a LazyMVar

It is not guaranteed that the LazyMVar contains a value that is in WHNF, so there is no guarantee that the resulting StrictMVar contains a value that is in WHNF. This should be used with caution.

The resulting StrictMVar has a trivial invariant.

unsafeToUncheckedStrictMVar ∷ ∀ (m ∷ TypeType) a. StrictMVar m a → StrictMVar m a Source #

Create an unchecked reference to the given checked StrictMVar.

Note that the invariant is only guaranteed when modifying the checked MVar. Any modification to the unchecked reference might break the invariants.

Orphan instances