projects
/
ghc-base.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
withThread: block asynchronous exceptions before installing exception handler.
[ghc-base.git]
/
Control
/
Concurrent.hs
diff --git
a/Control/Concurrent.hs
b/Control/Concurrent.hs
index
f22aca8
..
a25e659
100644
(file)
--- a/
Control/Concurrent.hs
+++ b/
Control/Concurrent.hs
@@
-1,3
+1,4
@@
+{-# OPTIONS_GHC -fno-warn-unused-imports #-}
-----------------------------------------------------------------------------
-- |
-- Module : Control.Concurrent
-----------------------------------------------------------------------------
-- |
-- Module : Control.Concurrent
@@
-99,9
+100,8
@@
import GHC.Exception
import GHC.Conc ( ThreadId(..), myThreadId, killThread, yield,
threadDelay, forkIO, childHandler )
import qualified GHC.Conc
import GHC.Conc ( ThreadId(..), myThreadId, killThread, yield,
threadDelay, forkIO, childHandler )
import qualified GHC.Conc
-import GHC.IOBase ( IO(..) )
-import GHC.IOBase ( unsafeInterleaveIO )
-import GHC.IOBase ( newIORef, readIORef, writeIORef )
+import GHC.IO ( IO(..), unsafeInterleaveIO )
+import GHC.IORef ( newIORef, readIORef, writeIORef )
import GHC.Base
import System.Posix.Types ( Fd )
import GHC.Base
import System.Posix.Types ( Fd )
@@
-112,7
+112,6
@@
import Control.Monad ( when )
#ifdef mingw32_HOST_OS
import Foreign.C
import System.IO
#ifdef mingw32_HOST_OS
import Foreign.C
import System.IO
-import GHC.Handle
#endif
#endif
#endif
#endif
@@
-431,7
+430,10
@@
runInUnboundThread action = do
if bound
then do
mv <- newEmptyMVar
if bound
then do
mv <- newEmptyMVar
- forkIO (Exception.try action >>= putMVar mv)
+ b <- blocked
+ _ <- block $ forkIO $
+ Exception.try (if b then action else unblock action) >>=
+ putMVar mv
takeMVar mv >>= \ei -> case ei of
Left exception -> Exception.throw (exception :: SomeException)
Right result -> return result
takeMVar mv >>= \ei -> case ei of
Left exception -> Exception.throw (exception :: SomeException)
Right result -> return result
@@
-454,7
+456,8
@@
threadWaitRead fd
-- and this only works with -threaded.
| threaded = withThread (waitFd fd 0)
| otherwise = case fd of
-- and this only works with -threaded.
| threaded = withThread (waitFd fd 0)
| otherwise = case fd of
- 0 -> do hWaitForInput stdin (-1); return ()
+ 0 -> do _ <- hWaitForInput stdin (-1)
+ return ()
-- hWaitForInput does work properly, but we can only
-- do this for stdin since we know its FD.
_ -> error "threadWaitRead requires -threaded on Windows, or use System.IO.hWaitForInput"
-- hWaitForInput does work properly, but we can only
-- do this for stdin since we know its FD.
_ -> error "threadWaitRead requires -threaded on Windows, or use System.IO.hWaitForInput"
@@
-479,7
+482,7
@@
foreign import ccall unsafe "rtsSupportsBoundThreads" threaded :: Bool
withThread :: IO a -> IO a
withThread io = do
m <- newEmptyMVar
withThread :: IO a -> IO a
withThread io = do
m <- newEmptyMVar
- forkIO $ try io >>= putMVar m
+ _ <- block $ forkIO $ try io >>= putMVar m
x <- takeMVar m
case x of
Right a -> return a
x <- takeMVar m
case x of
Right a -> return a
@@
-487,11
+490,11
@@
withThread io = do
waitFd :: Fd -> CInt -> IO ()
waitFd fd write = do
waitFd :: Fd -> CInt -> IO ()
waitFd fd write = do
- throwErrnoIfMinus1 "fdReady" $
+ throwErrnoIfMinus1_ "fdReady" $
fdReady (fromIntegral fd) write (fromIntegral iNFINITE) 0
fdReady (fromIntegral fd) write (fromIntegral iNFINITE) 0
- return ()
-iNFINITE = 0xFFFFFFFF :: CInt -- urgh
+iNFINITE :: CInt
+iNFINITE = 0xFFFFFFFF -- urgh
foreign import ccall safe "fdReady"
fdReady :: CInt -> CInt -> CInt -> CInt -> IO CInt
foreign import ccall safe "fdReady"
fdReady :: CInt -> CInt -> CInt -> CInt -> IO CInt
@@
-523,7
+526,7
@@
foreign import ccall safe "fdReady"
The "System.IO" library manages multiplexing in its own way. On
Windows systems it uses @safe@ foreign calls to ensure that
threads doing I\/O operations don't block the whole runtime,
The "System.IO" library manages multiplexing in its own way. On
Windows systems it uses @safe@ foreign calls to ensure that
threads doing I\/O operations don't block the whole runtime,
- whereas on Unix systems all the currently blocked I\/O reqwests
+ whereas on Unix systems all the currently blocked I\/O requests
are managed by a single thread (the /IO manager thread/) using
@select@.
are managed by a single thread (the /IO manager thread/) using
@select@.