From dce7bd6af20658a7fb262c83b06e9196d70d8c1a Mon Sep 17 00:00:00 2001 From: sof Date: Mon, 25 Jan 1999 10:26:18 +0000 Subject: [PATCH] [project @ 1999-01-25 10:26:18 by sof] Added isEmptyChan --- ghc/lib/concurrent/Channel.lhs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/ghc/lib/concurrent/Channel.lhs b/ghc/lib/concurrent/Channel.lhs index f9293c5..fca29df 100644 --- a/ghc/lib/concurrent/Channel.lhs +++ b/ghc/lib/concurrent/Channel.lhs @@ -20,6 +20,8 @@ module Channel dupChan, -- :: Chan a -> IO (Chan a) unGetChan, -- :: Chan a -> a -> IO () + isEmptyChan, -- :: Chan a -> IO Bool + {- stream interface -} getChanContents, -- :: Chan a -> IO [a] writeList2Chan -- :: Chan a -> [a] -> IO () @@ -96,6 +98,14 @@ unGetChan (Chan read write) val = do putMVar new_read_end (ChItem val read_end) putMVar read new_read_end +isEmptyChan :: Chan a -> IO Bool +isEmptyChan (Chan read write) = do + r <- takeMVar read + w <- readMVar write + let eq = r == w + eq `seq` putMVar read r + return eq + \end{code} Operators for interfacing with functional streams. -- 1.7.10.4