Use explicit language extensions & remove extension fields from base.cabal
[ghc-base.git] / Control / Concurrent / SampleVar.hs
index ad89a95..ca68a38 100644 (file)
@@ -1,3 +1,5 @@
+{-# LANGUAGE CPP #-}
+
 -----------------------------------------------------------------------------
 -- |
 -- Module      :  Control.Concurrent.SampleVar
@@ -30,10 +32,14 @@ import Prelude
 
 import Control.Concurrent.MVar
 
-import Control.Exception ( block )
+import Control.Exception ( mask_ )
 
 import Data.Functor ( (<$>) )
 
+import Data.Typeable
+
+#include "Typeable.h"
+
 -- |
 -- Sample variables are slightly different from a normal 'MVar':
 -- 
@@ -58,6 +64,8 @@ newtype SampleVar a = SampleVar ( MVar ( Int    -- 1  == full
                                 )
     deriving (Eq)
 
+INSTANCE_TYPEABLE1(SampleVar,sampleVarTc,"SampleVar")
+
 -- |Build a new, empty, 'SampleVar'
 newEmptySampleVar :: IO (SampleVar a)
 newEmptySampleVar = do
@@ -72,8 +80,8 @@ newSampleVar a = do
 
 -- |If the SampleVar is full, leave it empty.  Otherwise, do nothing.
 emptySampleVar :: SampleVar a -> IO ()
-emptySampleVar (SampleVar v) = block $ do
-   s@(readers, var) <- block $ takeMVar v
+emptySampleVar (SampleVar v) = mask_ $ do
+   s@(readers, var) <- takeMVar v
    if readers > 0 then do
      _ <- takeMVar var
      putMVar v (0,var)
@@ -82,7 +90,7 @@ emptySampleVar (SampleVar v) = block $ do
 
 -- |Wait for a value to become available, then take it and return.
 readSampleVar :: SampleVar a -> IO a
-readSampleVar (SampleVar svar) = block $ do
+readSampleVar (SampleVar svar) = mask_ $ do
 --
 -- filled => make empty and grab sample
 -- not filled => try to grab value, empty when read val.
@@ -95,7 +103,7 @@ readSampleVar (SampleVar svar) = block $ do
 -- |Write a value into the 'SampleVar', overwriting any previous value that
 -- was there.
 writeSampleVar :: SampleVar a -> a -> IO ()
-writeSampleVar (SampleVar svar) v = block $ do
+writeSampleVar (SampleVar svar) v = mask_ $ do
 --
 -- filled => overwrite
 -- not filled => fill, write val
@@ -120,5 +128,5 @@ writeSampleVar (SampleVar svar) v = block $ do
 isEmptySampleVar :: SampleVar a -> IO Bool
 isEmptySampleVar (SampleVar svar) = do
    (readers, _) <- readMVar svar
-   return (readers == 0)
+   return (readers <= 0)