[commit: base] : Change GHC.Event.Manager.closeFd to unregister interest in the file with the backend. (cb0a73c)

Johan Tibell johan.tibell at gmail.com
Tue Feb 12 07:51:18 CET 2013


Repository : ssh://darcs.haskell.org//srv/darcs/packages/base

On branch  : 

http://hackage.haskell.org/trac/ghc/changeset/cb0a73c2abbfebf45486d3ac4edab1497955d418

>---------------------------------------------------------------

commit cb0a73c2abbfebf45486d3ac4edab1497955d418
Author: Andreas Voellmy <andreas.voellmy at gmail.com>
Date:   Fri Jan 4 07:17:29 2013 -0500

    Change GHC.Event.Manager.closeFd to unregister interest in the file with the backend.
    
    The file must not be closed when unregistering interest in the file with the backend, because otherwise the backend will likely encounter an error (invalid fd). Therefore, the close fd command is executed after the backend is updated.

>---------------------------------------------------------------

 GHC/Event/Manager.hs |   10 +++++++---
 1 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/GHC/Event/Manager.hs b/GHC/Event/Manager.hs
index 02feafb..fe6fb39 100644
--- a/GHC/Event/Manager.hs
+++ b/GHC/Event/Manager.hs
@@ -348,11 +348,15 @@ unregisterFd mgr reg = do
 closeFd :: EventManager -> (Fd -> IO ()) -> Fd -> IO ()
 closeFd mgr close fd = do
   fds <- modifyMVar (callbackTableVar mgr fd) $ \oldMap -> do
-    close fd
     case IM.delete (fromIntegral fd) oldMap of
-      (Nothing,  _)       -> return (oldMap, [])
+      (Nothing,  _)       -> do close fd
+                                return (oldMap, [])
       (Just fds, !newMap) -> do
-        when (eventsOf fds /= mempty) $ wakeManager mgr
+        let oldEvs = eventsOf fds
+        when (oldEvs /= mempty) $ do
+          I.modifyFd (emBackend mgr) fd oldEvs mempty
+          wakeManager mgr
+        close fd
         return (newMap, fds)
   forM_ fds $ \(FdData reg ev cb) -> cb reg (ev `mappend` evtClose)
 





More information about the ghc-commits mailing list