[project @ 2000-04-10 16:02:58 by simonpj]
[ghc-hetmet.git] / ghc / lib / std / PrelConc.lhs
index 10ebbe4..f096db1 100644 (file)
@@ -7,7 +7,7 @@
 Basic concurrency stuff
 
 \begin{code}
-{-# OPTIONS -fno-implicit-prelude #-}
+{-# OPTIONS -fcompiling-prelude -fno-implicit-prelude #-}
 
 module PrelConc
        ( ThreadId(..)
@@ -18,7 +18,12 @@ module PrelConc
        , raiseInThread -- :: ThreadId -> Exception -> IO ()
        , par           -- :: a -> b -> b
        , seq           -- :: a -> b -> b
-       {-threadDelay, threadWaitRead, threadWaitWrite,-}
+       , yield         -- :: IO ()
+
+       -- Waiting
+       , threadDelay           -- :: Int -> IO ()
+       , threadWaitRead        -- :: Int -> IO ()
+       , threadWaitWrite       -- :: Int -> IO ()
 
        -- MVars
        , MVar          -- abstract
@@ -39,7 +44,7 @@ import PrelIOBase     ( IO(..), MVar(..), unsafePerformIO )
 import PrelBase                ( Int(..) )
 import PrelException    ( Exception(..), AsyncException(..) )
 
-infixr 0 `par`
+infixr 0 `par`, `seq`
 \end{code}
 
 %************************************************************************
@@ -54,7 +59,7 @@ data ThreadId = ThreadId ThreadId#
 -- But since ThreadId# is unlifted, the Weak type must use open
 -- type variables.
 
---forkIO has now been hoisted out into the concurrent library.
+--forkIO has now been hoisted out into the Concurrent library.
 
 killThread :: ThreadId -> IO ()
 killThread (ThreadId id) = IO $ \ s ->
@@ -68,6 +73,10 @@ myThreadId :: IO ThreadId
 myThreadId = IO $ \s ->
    case (myThreadId# s) of (# s1, id #) -> (# s1, ThreadId id #)
 
+yield :: IO ()
+yield = IO $ \s -> 
+   case (yield# s) of s1 -> (# s1, () #)
+
 -- "seq" is defined a bit wierdly (see below)
 --
 -- The reason for the strange "0# -> parError" case is that
@@ -83,15 +92,9 @@ myThreadId = IO $ \s ->
 seq :: a -> b -> b
 seq  x y = case (seq#  x) of { 0# -> seqError; _ -> y }
 
-par :: a -> b -> b
-
 {-# INLINE par  #-}
-#if defined(__PARALLEL_HASKELL__) || defined (__GRANSIM__)
+par :: a -> b -> b
 par  x y = case (par# x) of { 0# -> parError; _ -> y }
-#else
-par  _ y = y
-#endif
-
 \end{code}
 
 %************************************************************************
@@ -111,9 +114,6 @@ writes.
 \begin{code}
 --Defined in IOBase to avoid cycle: data MVar a = MVar (SynchVar# RealWorld a)
 
-instance Eq (MVar a) where
-       (MVar mvar1#) == (MVar mvar2#) = sameMVar# mvar1# mvar2#
-
 newEmptyMVar  :: IO (MVar a)
 
 newEmptyMVar = IO $ \ s# ->
@@ -189,19 +189,9 @@ specified file descriptor is available for reading (just like select).
 @threadWaitWrite@ is similar, but for writing on a file descriptor.
 
 \begin{code}
-{- Not yet -- SDM 
 threadDelay, threadWaitRead, threadWaitWrite :: Int -> IO ()
 
-threadDelay (I# x#) = IO $ \ s# ->
-    case delay# x# s# of
-      s2# -> (# s2#, () #)
-
-threadWaitRead (I# x#) = IO $ \ s# -> 
-    case waitRead# x# s# of
-      s2# -> (# s2#, () #)
-
-threadWaitWrite (I# x#) = IO $ \ s# ->
-    case waitWrite# x# s# of
-      s2# -> (# s2#, () #)
--}
+threadDelay     (I# ms) = IO $ \s -> case delay# ms s     of s -> (# s, () #)
+threadWaitRead  (I# fd) = IO $ \s -> case waitRead# fd s  of s -> (# s, () #)
+threadWaitWrite (I# fd) = IO $ \s -> case waitWrite# fd s of s -> (# s, () #)
 \end{code}