File tree Expand file tree Collapse file tree 2 files changed +21
-0
lines changed
io-classes/src/Control/Concurrent/Class
io-sim/src/Control/Monad/IOSim Expand file tree Collapse file tree 2 files changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ module Control.Concurrent.Class.MonadMVar
77 ( MonadMVar (.. )
88 -- * non-standard extensions
99 , MonadInspectMVar (.. )
10+ , MonadTraceMVar (.. )
1011 , MonadLabelledMVar (.. )
1112 ) where
1213
@@ -16,6 +17,7 @@ import Control.Monad.Class.MonadThrow
1617import Control.Monad.Reader (ReaderT (.. ))
1718import Control.Monad.Trans (lift )
1819
20+ import Control.Concurrent.Class.MonadSTM (TraceValue )
1921import Data.Kind (Type )
2022
2123
@@ -205,6 +207,15 @@ instance MonadInspectMVar IO where
205207 type InspectMVarMonad IO = IO
206208 inspectMVar _ = tryReadMVar
207209
210+ class MonadTraceMVar m where
211+ traceMVarIO :: proxy
212+ -> MVar m a
213+ -> (Maybe (Maybe a ) -> Maybe a -> InspectMVarMonad m TraceValue )
214+ -> m ()
215+
216+ instance MonadTraceMVar IO where
217+ traceMVarIO = \ _ _ _ -> pure ()
218+
208219-- | Labelled `MVar`s
209220--
210221-- The `IO` instances is no-op, the `IOSim` instance enhances simulation trace.
Original file line number Diff line number Diff line change @@ -615,6 +615,16 @@ instance MonadInspectMVar (IOSim s) where
615615 MVarEmpty _ _ -> pure Nothing
616616 MVarFull x _ -> pure (Just x)
617617
618+ instance MonadTraceMVar (IOSim s ) where
619+ traceMVarIO _ (MVar mvar) f = traceTVarIO mvar traceMVarAsTVar
620+ where
621+ traceMVarAsTVar Nothing (MVarEmpty _ _) = f Nothing Nothing
622+ traceMVarAsTVar Nothing (MVarFull a _) = f Nothing (Just a)
623+ traceMVarAsTVar (Just (MVarEmpty _ _)) (MVarEmpty _ _) = f (Just Nothing ) Nothing
624+ traceMVarAsTVar (Just (MVarEmpty _ _)) (MVarFull a _) = f (Just Nothing ) (Just a)
625+ traceMVarAsTVar (Just (MVarFull a _)) (MVarEmpty _ _) = f (Just (Just a)) Nothing
626+ traceMVarAsTVar (Just (MVarFull a _)) (MVarFull a' _) = f (Just (Just a)) (Just a')
627+
618628instance MonadLabelledMVar (IOSim s ) where
619629 labelMVar = labelMVarDefault
620630
You can’t perform that action at this time.
0 commit comments