strict-checked-vars
Safe HaskellNone
LanguageHaskell2010

Control.Concurrent.Class.MonadMVar.Strict.Checked

Description

This module corresponds to Control.Concurrent.MVar in the base package.

This module can be used as a drop-in replacement for Control.Concurrent.Class.MonadMVar.Strict, but not the other way around.

Synopsis

StrictMVar

type LazyMVar (m :: Type -> Type) = MVar m #

data StrictMVar (m :: Type -> Type) 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.

castStrictMVar :: forall (m :: Type -> Type) (n :: Type -> Type) a. LazyMVar m ~ LazyMVar n => StrictMVar m a -> StrictMVar n a Source #

fromLazyMVar :: forall (m :: Type -> Type) 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.

modifyMVar :: (HasCallStack, MonadMVar m) => StrictMVar m a -> (a -> m (a, b)) -> m b Source #

modifyMVarMasked :: (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.

modifyMVar_ :: (HasCallStack, MonadMVar m) => StrictMVar m a -> (a -> m a) -> m () Source #

modifyMVar_ is defined in terms of modifyMVar.

newMVar :: MonadMVar m => a -> m (StrictMVar m a) Source #

newMVarWithInvariant :: (HasCallStack, MonadMVar m) => (a -> Maybe String) -> a -> m (StrictMVar m a) Source #

Create a StrictMVar with an invariant.

Contrary to functions that modify a StrictMVar, this function checks the invariant before putting the value in a new StrictMVar.

putMVar :: (HasCallStack, MonadMVar m) => StrictMVar m a -> a -> m () Source #

readMVar :: MonadMVar m => StrictMVar m a -> m a Source #

swapMVar :: (HasCallStack, MonadMVar m) => StrictMVar m a -> a -> m a Source #

takeMVar :: MonadMVar m => StrictMVar m a -> m a Source #

toLazyMVar :: forall (m :: Type -> Type) 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.

unsafeToUncheckedStrictMVar :: forall (m :: Type -> Type) 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.

withMVar :: MonadMVar m => StrictMVar m a -> (a -> m b) -> m b Source #

withMVarMasked :: MonadMVar m => StrictMVar m a -> (a -> m b) -> m b Source #

Invariant

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.

Re-exports

class Monad m => MonadMVar (m :: Type -> Type) #

Instances

Instances details
MonadMVar IO # 
Instance details

Defined in Control.Concurrent.Class.MonadMVar

Associated Types

type MVar IO 
Instance details

Defined in Control.Concurrent.Class.MonadMVar

type MVar IO = MVar

Methods

newEmptyMVar :: IO (MVar IO a) #

takeMVar :: MVar IO a -> IO a #

putMVar :: MVar IO a -> a -> IO () #

tryTakeMVar :: MVar IO a -> IO (Maybe a) #

tryPutMVar :: MVar IO a -> a -> IO Bool #

isEmptyMVar :: MVar IO a -> IO Bool #

newMVar :: a -> IO (MVar IO a) #

readMVar :: MVar IO a -> IO a #

tryReadMVar :: MVar IO a -> IO (Maybe a) #

swapMVar :: MVar IO a -> a -> IO a #

withMVar :: MVar IO a -> (a -> IO b) -> IO b #

withMVarMasked :: MVar IO a -> (a -> IO b) -> IO b #

modifyMVar_ :: MVar IO a -> (a -> IO a) -> IO () #

modifyMVar :: MVar IO a -> (a -> IO (a, b)) -> IO b #

modifyMVarMasked_ :: MVar IO a -> (a -> IO a) -> IO () #

modifyMVarMasked :: MVar IO a -> (a -> IO (a, b)) -> IO b #

(MonadMask m, MonadMVar m) => MonadMVar (ReaderT r m) # 
Instance details

Defined in Control.Concurrent.Class.MonadMVar

Associated Types

type MVar (ReaderT r m) 
Instance details

Defined in Control.Concurrent.Class.MonadMVar

type MVar (ReaderT r m) = WrappedMVar r m

Methods

newEmptyMVar :: ReaderT r m (MVar (ReaderT r m) a) #

takeMVar :: MVar (ReaderT r m) a -> ReaderT r m a #

putMVar :: MVar (ReaderT r m) a -> a -> ReaderT r m () #

tryTakeMVar :: MVar (ReaderT r m) a -> ReaderT r m (Maybe a) #

tryPutMVar :: MVar (ReaderT r m) a -> a -> ReaderT r m Bool #

isEmptyMVar :: MVar (ReaderT r m) a -> ReaderT r m Bool #

newMVar :: a -> ReaderT r m (MVar (ReaderT r m) a) #

readMVar :: MVar (ReaderT r m) a -> ReaderT r m a #

tryReadMVar :: MVar (ReaderT r m) a -> ReaderT r m (Maybe a) #

swapMVar :: MVar (ReaderT r m) a -> a -> ReaderT r m a #

withMVar :: MVar (ReaderT r m) a -> (a -> ReaderT r m b) -> ReaderT r m b #

withMVarMasked :: MVar (ReaderT r m) a -> (a -> ReaderT r m b) -> ReaderT r m b #

modifyMVar_ :: MVar (ReaderT r m) a -> (a -> ReaderT r m a) -> ReaderT r m () #

modifyMVar :: MVar (ReaderT r m) a -> (a -> ReaderT r m (a, b)) -> ReaderT r m b #

modifyMVarMasked_ :: MVar (ReaderT r m) a -> (a -> ReaderT r m a) -> ReaderT r m () #

modifyMVarMasked :: MVar (ReaderT r m) a -> (a -> ReaderT r m (a, b)) -> ReaderT r m b #