| Safe Haskell | Trustworthy |
|---|
LIO.Concurrent.LMVar
Description
This module implements labeled MVars. The interface is analogous to
Control.Concurrent.MVar, but the operations take place in the LIO
monad. A labeled MVar, of type , is a mutable location
that can be in of of two states; an LMVar l aLMVar can be empty, or it can be
full (with a value of tye a). The location is protected by a label
of type l. As in the case of LIORefs (see LIO.LIORef), this
label is fixed and does not change according to the content placed
into the location. Different from LIORefs, taking and putting
LMVars calls the write guard guardWrite to enforce sound
information flow control.
LMVars can be used to build synchronization primitives and
communication channels (LMVars themselves are single-place
channels). We refer to Control.Concurrent.MVar for the full
documentation on MVars.
- data LMVar l a
- newEmptyLMVar :: MonadLIO l m => l -> m (LMVar l a)
- newEmptyLMVarP :: (MonadLIO l m, Priv l p) => p -> l -> m (LMVar l a)
- newLMVar :: Label l => l -> a -> LIO l (LMVar l a)
- newLMVarP :: (MonadLIO l m, Priv l p) => p -> l -> a -> m (LMVar l a)
- takeLMVar :: MonadLIO l m => LMVar l a -> m a
- takeLMVarP :: (MonadLIO l m, Priv l p) => p -> LMVar l a -> m a
- tryTakeLMVar :: MonadLIO l m => LMVar l a -> m (Maybe a)
- tryTakeLMVarP :: (MonadLIO l m, Priv l p) => p -> LMVar l a -> m (Maybe a)
- putLMVar :: Label l => LMVar l a -> a -> LIO l ()
- putLMVarP :: (MonadLIO l m, Priv l p) => p -> LMVar l a -> a -> m ()
- tryPutLMVar :: MonadLIO l m => LMVar l a -> a -> m Bool
- tryPutLMVarP :: (MonadLIO l m, Priv l p) => p -> LMVar l a -> a -> m Bool
- readLMVar :: MonadLIO l m => LMVar l a -> m a
- readLMVarP :: (MonadLIO l m, Priv l p) => p -> LMVar l a -> m a
- swapLMVar :: Label l => LMVar l a -> a -> LIO l a
- swapLMVarP :: (MonadLIO l m, Priv l p) => p -> LMVar l a -> a -> m a
- isEmptyLMVar :: MonadLIO l m => LMVar l a -> m Bool
- isEmptyLMVarP :: (MonadLIO l m, Priv l p) => p -> LMVar l a -> m Bool
Documentation
An LMVar is a labeled synchronization variable (an MVar) that
can be used by concurrent threads to communicate.
Creating labeled MVars
Create a new labeled MVar, in an empty state. Note that the supplied
label must be above the current label and below the current clearance.
An exception will be thrown by the underlying guardAlloc if this is
not the case.
newEmptyLMVarP :: (MonadLIO l m, Priv l p) => p -> l -> m (LMVar l a)Source
Same as newEmptyLMVar except it takes a set of privileges which
are accounted for in comparing the label of the MVar to the current
label and clearance.
Arguments
| :: Label l | |
| => l | Label of |
| -> a | Initial value of |
| -> LIO l (LMVar l a) | New mutable location |
Create a new labeled MVar, in an filled state with the supplied value. Note that the supplied label must be above the current label and below the current clearance.
newLMVarP :: (MonadLIO l m, Priv l p) => p -> l -> a -> m (LMVar l a)Source
Same as newLMVar except it takes a set of privileges which are
accounted for in comparing the label of the MVar to the current label
and clearance.
Take LMVar
takeLMVar :: MonadLIO l m => LMVar l a -> m aSource
Return contents of the LMVar. Note that a take consists of a read
and a write, since it observes whether or not the LMVar is full, and
thus the current label must be the same as that of the LMVar (of
course, this is not the case when using privileges). Hence, if the
label of the LMVar is below the current clearance, we raise the
current label to the join of the current label and the label of the
MVar and read the contents of the MVar. The underlying guard
guardWrite will throw an exception if any of the IFC checks fail.
If the Finally, like MVars if the LMVar is empty, takeLMVar
blocks.
takeLMVarP :: (MonadLIO l m, Priv l p) => p -> LMVar l a -> m aSource
Same as takeLMVar except takeLMVarP takes a privilege object
which is used when the current label is raised.
tryTakeLMVar :: MonadLIO l m => LMVar l a -> m (Maybe a)Source
tryTakeLMVarP :: (MonadLIO l m, Priv l p) => p -> LMVar l a -> m (Maybe a)Source
Same as tryTakeLMVar, but uses priviliges when raising current
label.
Put LMVar
Puts a value into an LMVar. Note that a put consists of a read and
a write, since it observes whether or not the LMVar is empty, and so
the current label must be the same as that of the LMVar (of course,
this is not the case when using privileges). As in the takeLMVar
case, if the label of the LMVar is below the current clearance, we
raise the current label to the join of the current label and the label
of the MVar and put the value into the MVar. Moreover if these IFC
restrictions fail, the underlying guardWrite throws an exception.
If the LMVar is full, putLMVar blocks.
putLMVarP :: (MonadLIO l m, Priv l p) => p -> LMVar l a -> a -> m ()Source
Same as putLMVar except putLMVarP takes a privilege object
which is used when the current label is raised.
Read LMVar
tryPutLMVar :: MonadLIO l m => LMVar l a -> a -> m BoolSource
tryPutLMVarP :: (MonadLIO l m, Priv l p) => p -> LMVar l a -> a -> m BoolSource
Same as tryPutLMVar, but uses privileges when raising current label.
readLMVarP :: (MonadLIO l m, Priv l p) => p -> LMVar l a -> m aSource
Same as readLMVar except readLMVarP takes a privilege object
which is used when the current label is raised.
Swap LMVar
Takes a value from an LMVar, puts a new value into the LMvar,
and returns the taken value. Like the other LMVar operations it is
required that the label of the LMVar be above the current label and
below the current clearance. Moreover, the current label is raised to
accommodate for the observation. The underlying guardWrite throws an
exception if this cannot be accomplished. This operation is atomic iff
there is no other thread calling putLMVar for this LMVar.
swapLMVarP :: (MonadLIO l m, Priv l p) => p -> LMVar l a -> a -> m aSource
Same as swapLMVar except swapLMVarP takes a privilege object
which is used when the current label is raised.
Check state of LMVar
isEmptyLMVar :: MonadLIO l m => LMVar l a -> m BoolSource
Check the status of an LMVar, i.e., whether it is empty. The
function succeeds if the label of the LMVar is below the current
clearance -- the current label is raised to the join of the LMVar
label and the current label. Note that this function only returns a
snapshot of the state and does not modify it -- hence the
underlying guard is taint and not guardWrite.
isEmptyLMVarP :: (MonadLIO l m, Priv l p) => p -> LMVar l a -> m BoolSource
Same as isEmptyLMVar, but uses privileges when raising current label.