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
7
7
( MonadMVar (.. )
8
8
-- * non-standard extensions
9
9
, MonadInspectMVar (.. )
10
+ , MonadTraceMVar (.. )
10
11
, MonadLabelledMVar (.. )
11
12
) where
12
13
@@ -16,6 +17,7 @@ import Control.Monad.Class.MonadThrow
16
17
import Control.Monad.Reader (ReaderT (.. ))
17
18
import Control.Monad.Trans (lift )
18
19
20
+ import Control.Concurrent.Class.MonadSTM (TraceValue )
19
21
import Data.Kind (Type )
20
22
21
23
@@ -205,6 +207,15 @@ instance MonadInspectMVar IO where
205
207
type InspectMVarMonad IO = IO
206
208
inspectMVar _ = tryReadMVar
207
209
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
+
208
219
-- | Labelled `MVar`s
209
220
--
210
221
-- 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
615
615
MVarEmpty _ _ -> pure Nothing
616
616
MVarFull x _ -> pure (Just x)
617
617
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
+
618
628
instance MonadLabelledMVar (IOSim s ) where
619
629
labelMVar = labelMVarDefault
620
630
You can’t perform that action at this time.
0 commit comments