From: Bryan O'Sullivan Date: Mon, 6 Dec 2010 00:41:24 +0000 (+0000) Subject: Drop closeFd from Control.Concurrent, rename to closeFdWith X-Git-Url: http://git.megacz.com/?p=ghc-base.git;a=commitdiff_plain;h=b22112520b01c4906eebd0b6894d4bf2665c11e2 Drop closeFd from Control.Concurrent, rename to closeFdWith --- diff --git a/Control/Concurrent.hs b/Control/Concurrent.hs index b49f7db..d1b6875 100644 --- a/Control/Concurrent.hs +++ b/Control/Concurrent.hs @@ -47,7 +47,6 @@ module Control.Concurrent ( threadDelay, -- :: Int -> IO () threadWaitRead, -- :: Int -> IO () threadWaitWrite, -- :: Int -> IO () - closeFd, -- :: (Int -> IO ()) -> Int -> IO () #endif -- * Communication abstractions @@ -454,7 +453,9 @@ unsafeResult = either Exception.throwIO return -- given file descriptor (GHC only). -- -- This will throw an 'IOError' if the file descriptor was closed --- while this thread was blocked. +-- while this thread was blocked. To safely close a file descriptor +-- that has been used with 'threadWaitRead', use +-- 'GHC.Conc.closeFdWith'. threadWaitRead :: Fd -> IO () threadWaitRead fd #ifdef mingw32_HOST_OS @@ -477,7 +478,9 @@ threadWaitRead fd -- given file descriptor (GHC only). -- -- This will throw an 'IOError' if the file descriptor was closed --- while this thread was blocked. +-- while this thread was blocked. To safely close a file descriptor +-- that has been used with 'threadWaitWrite', use +-- 'GHC.Conc.closeFdWith'. threadWaitWrite :: Fd -> IO () threadWaitWrite fd #ifdef mingw32_HOST_OS @@ -487,24 +490,6 @@ threadWaitWrite fd = GHC.Conc.threadWaitWrite fd #endif --- | Close a file descriptor in a concurrency-safe way (GHC only). If --- you are using 'threadWaitRead' or 'threadWaitWrite' to perform --- blocking I\/O, you /must/ use this function to close file --- descriptors, or blocked threads may not be woken. --- --- Any threads that are blocked on the file descriptor via --- 'threadWaitRead' or 'threadWaitWrite' will be unblocked by having --- IO exceptions thrown. -closeFd :: (Fd -> IO ()) -- ^ Low-level action that performs the real close. - -> Fd -- ^ File descriptor to close. - -> IO () -closeFd close fd -#ifdef mingw32_HOST_OS - = close fd -#else - = GHC.Conc.closeFd close fd -#endif - #ifdef mingw32_HOST_OS foreign import ccall unsafe "rtsSupportsBoundThreads" threaded :: Bool diff --git a/GHC/Conc.lhs b/GHC/Conc.lhs index a7f6902..b12785f 100644 --- a/GHC/Conc.lhs +++ b/GHC/Conc.lhs @@ -52,7 +52,7 @@ module GHC.Conc , registerDelay -- :: Int -> IO (TVar Bool) , threadWaitRead -- :: Int -> IO () , threadWaitWrite -- :: Int -> IO () - , closeFd -- :: (Int -> IO ()) -> Int -> IO () + , closeFdWith -- :: (Fd -> IO ()) -> Fd -> IO () -- * TVars , STM(..) diff --git a/GHC/Conc/IO.hs b/GHC/Conc/IO.hs index 5a5f0b2..ca75894 100644 --- a/GHC/Conc/IO.hs +++ b/GHC/Conc/IO.hs @@ -31,7 +31,7 @@ module GHC.Conc.IO , registerDelay -- :: Int -> IO (TVar Bool) , threadWaitRead -- :: Int -> IO () , threadWaitWrite -- :: Int -> IO () - , closeFd -- :: (Int -> IO ()) -> Int -> IO () + , closeFdWith -- :: (Fd -> IO ()) -> Fd -> IO () #ifdef mingw32_HOST_OS , asyncRead -- :: Int -> Int -> Int -> Ptr a -> IO (Int, Int) @@ -71,6 +71,10 @@ ensureIOManagerIsRunning = Windows.ensureIOManagerIsRunning -- | Block the current thread until data is available to read on the -- given file descriptor (GHC only). +-- +-- This will throw an 'IOError' if the file descriptor was closed +-- while this thread was blocked. To safely close a file descriptor +-- that has been used with 'threadWaitRead', use 'closeFdWith'. threadWaitRead :: Fd -> IO () threadWaitRead fd #ifndef mingw32_HOST_OS @@ -85,7 +89,8 @@ threadWaitRead fd -- given file descriptor (GHC only). -- -- This will throw an 'IOError' if the file descriptor was closed --- while this thread was blocked. +-- while this thread was blocked. To safely close a file descriptor +-- that has been used with 'threadWaitWrite', use 'closeFdWith'. threadWaitWrite :: Fd -> IO () threadWaitWrite fd #ifndef mingw32_HOST_OS @@ -104,12 +109,12 @@ threadWaitWrite fd -- Any threads that are blocked on the file descriptor via -- 'threadWaitRead' or 'threadWaitWrite' will be unblocked by having -- IO exceptions thrown. -closeFd :: (Fd -> IO ()) -- ^ Low-level action that performs the real close. - -> Fd -- ^ File descriptor to close. - -> IO () -closeFd close fd +closeFdWith :: (Fd -> IO ()) -- ^ Low-level action that performs the real close. + -> Fd -- ^ File descriptor to close. + -> IO () +closeFdWith close fd #ifndef mingw32_HOST_OS - | threaded = Event.closeFd close fd + | threaded = Event.closeFdWith close fd #endif | otherwise = close fd diff --git a/GHC/IO/FD.hs b/GHC/IO/FD.hs index 17362dc..3ba155e 100644 --- a/GHC/IO/FD.hs +++ b/GHC/IO/FD.hs @@ -289,7 +289,7 @@ close fd = else #endif c_close (fromIntegral realFd) - closeFd closer (fromIntegral (fdFD fd)) + closeFdWith closer (fromIntegral (fdFD fd)) release :: FD -> IO () #ifdef mingw32_HOST_OS diff --git a/System/Event/Thread.hs b/System/Event/Thread.hs index 66174cd..4c2170d 100644 --- a/System/Event/Thread.hs +++ b/System/Event/Thread.hs @@ -5,7 +5,7 @@ module System.Event.Thread ensureIOManagerIsRunning , threadWaitRead , threadWaitWrite - , closeFd + , closeFdWith , threadDelay , registerDelay ) where @@ -57,7 +57,8 @@ registerDelay usecs = do -- given file descriptor. -- -- This will throw an 'IOError' if the file descriptor was closed --- while this thread is blocked. +-- while this thread was blocked. To safely close a file descriptor +-- that has been used with 'threadWaitRead', use 'closeFdWith'. threadWaitRead :: Fd -> IO () threadWaitRead = threadWait evtRead {-# INLINE threadWaitRead #-} @@ -66,7 +67,8 @@ threadWaitRead = threadWait evtRead -- accept data to write. -- -- This will throw an 'IOError' if the file descriptor was closed --- while this thread is blocked. +-- while this thread was blocked. To safely close a file descriptor +-- that has been used with 'threadWaitWrite', use 'closeFdWith'. threadWaitWrite :: Fd -> IO () threadWaitWrite = threadWait evtWrite {-# INLINE threadWaitWrite #-} @@ -76,10 +78,10 @@ threadWaitWrite = threadWait evtWrite -- Any threads that are blocked on the file descriptor via -- 'threadWaitRead' or 'threadWaitWrite' will be unblocked by having -- IO exceptions thrown. -closeFd :: (Fd -> IO ()) -- ^ Action that performs the close. - -> Fd -- ^ File descriptor to close. - -> IO () -closeFd close fd = do +closeFdWith :: (Fd -> IO ()) -- ^ Action that performs the close. + -> Fd -- ^ File descriptor to close. + -> IO () +closeFdWith close fd = do Just mgr <- readIORef eventManager M.closeFd mgr close fd