Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
StrictMVar
s 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
- newEmptyMVar ∷ (MonadMVar m, NoThunks a) ⇒ m (StrictMVar m a)
- newEmptyMVarWithInvariant ∷ (MonadMVar m, NoThunks a) ⇒ (a → Maybe String) → m (StrictMVar m a)
- newMVar ∷ (HasCallStack, MonadMVar m, NoThunks a) ⇒ a → m (StrictMVar m a)
- newMVarWithInvariant ∷ (HasCallStack, MonadMVar m, NoThunks a) ⇒ (a → Maybe String) → a → m (StrictMVar m a)
- noThunksInvariant ∷ NoThunks a ⇒ a → Maybe String
- uncheckedNewEmptyMVar ∷ MonadMVar m ⇒ m (StrictMVar m a)
- uncheckedNewMVar ∷ MonadMVar m ⇒ a → m (StrictMVar m a)
- class Monad m ⇒ MonadMVar (m ∷ Type → Type)
- type LazyMVar (m ∷ Type → Type) = MVar m
- data StrictMVar (m ∷ Type → Type) a
- checkInvariant ∷ HasCallStack ⇒ Maybe String → a → a
- takeMVar ∷ MonadMVar m ⇒ StrictMVar m a → m a
- readMVar ∷ MonadMVar m ⇒ StrictMVar m a → m a
- putMVar ∷ (HasCallStack, MonadMVar m) ⇒ StrictMVar m a → a → m ()
- tryTakeMVar ∷ MonadMVar m ⇒ StrictMVar m a → m (Maybe a)
- tryPutMVar ∷ (HasCallStack, MonadMVar m) ⇒ StrictMVar m a → a → m Bool
- tryReadMVar ∷ MonadMVar m ⇒ StrictMVar m a → m (Maybe a)
- isEmptyMVar ∷ MonadMVar m ⇒ StrictMVar m a → m Bool
- withMVar ∷ MonadMVar m ⇒ StrictMVar m a → (a → m b) → m b
- modifyMVar_ ∷ (HasCallStack, MonadMVar m) ⇒ StrictMVar m a → (a → m a) → m ()
- swapMVar ∷ (HasCallStack, MonadMVar m) ⇒ StrictMVar m a → a → m a
- withMVarMasked ∷ MonadMVar m ⇒ StrictMVar m a → (a → m b) → m b
- modifyMVar ∷ (HasCallStack, MonadMVar m) ⇒ StrictMVar m a → (a → m (a, b)) → m b
- modifyMVarMasked_ ∷ (HasCallStack, MonadMVar m) ⇒ StrictMVar m a → (a → m a) → m ()
- modifyMVarMasked ∷ (HasCallStack, MonadMVar m) ⇒ StrictMVar m a → (a → m (a, b)) → m b
- castStrictMVar ∷ ∀ (m ∷ Type → Type) (n ∷ Type → Type) a. LazyMVar m ~ LazyMVar n ⇒ StrictMVar m a → StrictMVar n a
- toLazyMVar ∷ ∀ (m ∷ Type → Type) a. StrictMVar m a → LazyMVar m a
- fromLazyMVar ∷ ∀ (m ∷ Type → Type) a. LazyMVar m a → StrictMVar m a
- unsafeToUncheckedStrictMVar ∷ ∀ (m ∷ Type → Type) a. StrictMVar m a → StrictMVar m a
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
uncheckedNewEmptyMVar ∷ MonadMVar m ⇒ m (StrictMVar m a) Source #
Like newEmptyMVar
, but without a NoThunks
invariant.
uncheckedNewMVar ∷ MonadMVar m ⇒ a → m (StrictMVar m a) Source #
Re-exports
class Monad m ⇒ MonadMVar (m ∷ Type → Type) Source #
Instances
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.
Instances
NoThunks (StrictMVar IO a) ⇒ NoThunks (StrictMVar IO a) 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.
takeMVar ∷ MonadMVar m ⇒ StrictMVar m a → m a Source #
readMVar ∷ MonadMVar m ⇒ StrictMVar m a → m a Source #
putMVar ∷ (HasCallStack, MonadMVar m) ⇒ StrictMVar m a → a → m () Source #
tryTakeMVar ∷ MonadMVar m ⇒ StrictMVar m a → m (Maybe a) Source #
tryPutMVar ∷ (HasCallStack, MonadMVar m) ⇒ StrictMVar m a → a → m Bool Source #
tryReadMVar ∷ MonadMVar m ⇒ StrictMVar m a → m (Maybe a) Source #
isEmptyMVar ∷ MonadMVar m ⇒ StrictMVar m a → m Bool Source #
withMVar ∷ MonadMVar 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 #
withMVarMasked ∷ MonadMVar 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 ∷ Type → Type) (n ∷ Type → Type) a. LazyMVar m ~ LazyMVar n ⇒ StrictMVar m a → StrictMVar n a Source #
toLazyMVar ∷ ∀ (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.
fromLazyMVar ∷ ∀ (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.
unsafeToUncheckedStrictMVar ∷ ∀ (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.