@@ -76,11 +76,17 @@ type LazyTMVar m = Lazy.TMVar m
76
76
Strict TVar
77
77
-------------------------------------------------------------------------------}
78
78
79
+ #if CHECK_TVAR_INVARIANT
79
80
data StrictTVar m a = StrictTVar
80
81
{ invariant :: ! (a -> Maybe String )
81
82
-- ^ Invariant checked whenever updating the 'StrictTVar'.
82
83
, tvar :: ! (LazyTVar m a )
83
84
}
85
+ #else
86
+ newtype StrictTVar m a = StrictTVar
87
+ { tvar :: LazyTVar m a
88
+ }
89
+ #endif
84
90
85
91
labelTVar :: MonadLabelledSTM m => StrictTVar m a -> String -> STM m ()
86
92
labelTVar StrictTVar { tvar } = Lazy. labelTVar tvar
@@ -90,7 +96,11 @@ labelTVarIO v = atomically . labelTVar v
90
96
91
97
castStrictTVar :: LazyTVar m ~ LazyTVar n
92
98
=> StrictTVar m a -> StrictTVar n a
99
+ #if CHECK_TVAR_INVARIANT
93
100
castStrictTVar StrictTVar {invariant, tvar} = StrictTVar {invariant, tvar}
101
+ #else
102
+ castStrictTVar StrictTVar { tvar} = StrictTVar { tvar}
103
+ #endif
94
104
95
105
-- | Get the underlying @TVar@
96
106
--
@@ -100,7 +110,11 @@ toLazyTVar :: StrictTVar m a -> LazyTVar m a
100
110
toLazyTVar StrictTVar { tvar } = tvar
101
111
102
112
newTVar :: MonadSTM m => a -> STM m (StrictTVar m a )
113
+ #if CHECK_TVAR_INVARIANT
103
114
newTVar ! a = StrictTVar (const Nothing ) <$> Lazy. newTVar a
115
+ #else
116
+ newTVar ! a = StrictTVar <$> Lazy. newTVar a
117
+ #endif
104
118
105
119
newTVarIO :: MonadSTM m => a -> m (StrictTVar m a )
106
120
newTVarIO = newTVarWithInvariantIO (const Nothing )
@@ -113,9 +127,14 @@ newTVarWithInvariantIO :: (MonadSTM m, HasCallStack)
113
127
=> (a -> Maybe String ) -- ^ Invariant (expect 'Nothing')
114
128
-> a
115
129
-> m (StrictTVar m a )
116
- newTVarWithInvariantIO invariant ! a =
130
+ #if CHECK_TVAR_INVARIANT
131
+ newTVarWithInvariantIO invariant ! a =
117
132
checkInvariant (invariant a) $
118
133
StrictTVar invariant <$> Lazy. newTVarIO a
134
+ #else
135
+ newTVarWithInvariantIO _invariant ! a =
136
+ StrictTVar <$> Lazy. newTVarIO a
137
+ #endif
119
138
120
139
newTVarWithInvariantM :: (MonadSTM m , HasCallStack )
121
140
=> (a -> Maybe String ) -- ^ Invariant (expect 'Nothing')
@@ -131,9 +150,11 @@ readTVarIO :: MonadSTM m => StrictTVar m a -> m a
131
150
readTVarIO StrictTVar { tvar } = Lazy. readTVarIO tvar
132
151
133
152
writeTVar :: (MonadSTM m , HasCallStack ) => StrictTVar m a -> a -> STM m ()
134
- writeTVar StrictTVar { tvar, invariant } ! a =
135
- checkInvariant (invariant a) $
136
- Lazy. writeTVar tvar a
153
+ writeTVar v ! a =
154
+ #if CHECK_TVAR_INVARIANT
155
+ checkInvariant (invariant v a) $
156
+ #endif
157
+ Lazy. writeTVar (tvar v) a
137
158
138
159
modifyTVar :: MonadSTM m => StrictTVar m a -> (a -> a ) -> STM m ()
139
160
modifyTVar v f = readTVar v >>= writeTVar v . f
0 commit comments