module Simulation.Aivika.Trans.Concurrent.MVar
(withMVarComp,
withMVarParameter,
withMVarSimulation,
withMVarDynamics,
withMVarEvent,
withMVarProcess) where
import Control.Concurrent.MVar
import Control.Monad
import Control.Monad.Trans
import Simulation.Aivika.Trans.Exception
import Simulation.Aivika.Trans.Comp
import Simulation.Aivika.Trans.DES
import Simulation.Aivika.Trans.Parameter
import Simulation.Aivika.Trans.Simulation
import Simulation.Aivika.Trans.Dynamics
import Simulation.Aivika.Trans.Event
import Simulation.Aivika.Trans.Process
withMVarComp :: (MonadComp m, MonadIO m) => MVar a -> (a -> m b) -> m b
withMVarComp v f =
do a <- liftIO $ takeMVar v
finallyComp
(f a)
(liftIO $ putMVar v a)
withMVarParameter :: (MonadComp m, MonadIO m) => MVar a -> (a -> Parameter m b) -> Parameter m b
withMVarParameter v f =
do a <- liftIO $ takeMVar v
finallyParameter
(f a)
(liftIO $ putMVar v a)
withMVarSimulation :: (MonadComp m, MonadIO m) => MVar a -> (a -> Simulation m b) -> Simulation m b
withMVarSimulation v f =
do a <- liftIO $ takeMVar v
finallySimulation
(f a)
(liftIO $ putMVar v a)
withMVarDynamics :: (MonadComp m, MonadIO m) => MVar a -> (a -> Dynamics m b) -> Dynamics m b
withMVarDynamics v f =
do a <- liftIO $ takeMVar v
finallyDynamics
(f a)
(liftIO $ putMVar v a)
withMVarEvent :: (MonadComp m, MonadIO m) => MVar a -> (a -> Event m b) -> Event m b
withMVarEvent v f =
do a <- liftIO $ takeMVar v
finallyEvent
(f a)
(liftIO $ putMVar v a)
withMVarProcess :: (MonadDES m, MonadIO m) => MVar a -> (a -> Process m b) -> Process m b
withMVarProcess v f =
do a <- liftIO $ takeMVar v
finallyProcess
(f a)
(liftIO $ putMVar v a)