+{-
%
% (c) The GRASP/AQUA Project, Glasgow University, 1995
%
\item Writing to a filled @SampleVar@ overwrites the current value.
(different from @putMVar@ on full @MVar@.)
\end{itemize}
+-}
-\begin{code}
module SampleVar
(
- SampleVar(..), --:: type _ =
+ SampleVar, --:: type _ =
newSampleVar, --:: IO (SampleVar a)
emptySampleVar, --:: SampleVar a -> IO ()
) where
-import PreludeGlaST
-import PreludePrimIO ( newEmptyMVar, newMVar, putMVar,
- readMVar, swapMVar, takeMVar, _MVar
- )
-\end{code}
-
-\begin{code}
+import GHCbase
type SampleVar a
- = _MVar (Int, -- 1 == full
+ = MVar (Int, -- 1 == full
-- 0 == empty
-- <0 no of readers blocked
- _MVar a)
-
-\end{code}
+ MVar a)
-Initally, a @SampleVar@ is empty/unfilled.
-
-\begin{code}
+-- Initally, a @SampleVar@ is empty/unfilled.
newSampleVar :: IO (SampleVar a)
newSampleVar
else
putMVar v (readers,var)
-\end{code}
-
-
-
-\begin{code}
-
--
-- filled => make empty and grab sample
-- not filled => try to grab value, empty when read val.
_ ->
putMVar val v >>
putMVar svar (min 1 (readers+1), val)
-
-\end{code}