File tree Expand file tree Collapse file tree 1 file changed +17
-1
lines changed
strict-stm/src/Control/Monad/Class/MonadSTM Expand file tree Collapse file tree 1 file changed +17
-1
lines changed Original file line number Diff line number Diff line change @@ -18,6 +18,7 @@ module Control.Monad.Class.MonadSTM.Strict
18
18
, labelTVarIO
19
19
, castStrictTVar
20
20
, toLazyTVar
21
+ , fromLazyTVar
21
22
, newTVar
22
23
, newTVarIO
23
24
, newTVarWithInvariantIO
@@ -32,6 +33,8 @@ module Control.Monad.Class.MonadSTM.Strict
32
33
, labelTMVar
33
34
, labelTMVarIO
34
35
, castStrictTMVar
36
+ , toLazyTMVar
37
+ , fromLazyTMVar
35
38
, newTMVar
36
39
, newTMVarIO
37
40
, newEmptyTMVar
@@ -106,6 +109,16 @@ castStrictTVar v@StrictTVar {tvar} =
106
109
toLazyTVar :: StrictTVar m a -> LazyTVar m a
107
110
toLazyTVar StrictTVar { tvar } = tvar
108
111
112
+ fromLazyTVar :: LazyTVar m a -> StrictTVar m a
113
+ fromLazyTVar tvar =
114
+ #if CHECK_TVAR_INVARIANT
115
+ StrictTVar { invariant = const Nothing
116
+ , tvar
117
+ }
118
+ #else
119
+ StrictTVar { tvar }
120
+ #endif
121
+
109
122
newTVar :: MonadSTM m => a -> STM m (StrictTVar m a )
110
123
newTVar ! a = (\ tvar -> mkStrictTVar (const Nothing ) tvar)
111
124
<$> Lazy. newTVar a
@@ -174,7 +187,10 @@ updateTVar = stateTVar
174
187
-- Does not support an invariant: if the invariant would not be satisfied,
175
188
-- we would not be able to put a value into an empty TMVar, which would lead
176
189
-- to very hard to debug bugs where code is blocked indefinitely.
177
- newtype StrictTMVar m a = StrictTMVar (LazyTMVar m a )
190
+ newtype StrictTMVar m a = StrictTMVar { toLazyTMVar :: LazyTMVar m a }
191
+
192
+ fromLazyTMVar :: LazyTMVar m a -> StrictTMVar m a
193
+ fromLazyTMVar = StrictTMVar
178
194
179
195
labelTMVar :: MonadLabelledSTM m => StrictTMVar m a -> String -> STM m ()
180
196
labelTMVar (StrictTMVar tvar) = Lazy. labelTMVar tvar
You can’t perform that action at this time.
0 commit comments