+ 1 ->
+ swapMVar val v >>
+ putMVar svar s
+ _ ->
+ putMVar val v >>
+ let readers' = min 1 (readers+1)
+ in readers' `seq` putMVar svar (readers', val)
+
+-- | Returns 'True' if the 'SampleVar' is currently empty.
+--
+-- Note that this function is only useful if you know that no other
+-- threads can be modifying the state of the 'SampleVar', because
+-- otherwise the state of the 'SampleVar' may have changed by the time
+-- you see the result of 'isEmptySampleVar'.
+--
+isEmptySampleVar :: SampleVar a -> IO Bool
+isEmptySampleVar (SampleVar svar) = do
+ (readers, _) <- readMVar svar
+ return (readers <= 0)
+