Movatterモバイル変換
[0]ホーム
{-# LANGUAGE Trustworthy #-}{-# LANGUAGE CPP , NoImplicitPrelude , MagicHash , UnboxedTuples #-}{-# OPTIONS_GHC -Wno-missing-signatures #-}{-# OPTIONS_HADDOCK not-home #-}------------------------------------------------------------------------------- |-- Module : GHC.Conc.IO-- Copyright : (c) The University of Glasgow, 1994-2002-- License : see libraries/base/LICENSE---- Maintainer : cvs-ghc@haskell.org-- Stability : internal-- Portability : non-portable (GHC extensions)---- Basic concurrency stuff.--------------------------------------------------------------------------------- No: #hide, because bits of this module are exposed by the stm package.-- However, we don't want this module to be the home location for the-- bits it exports, we'd rather have Control.Concurrent and the other-- higher level modules be the home. Hence: #not-homemoduleGHC.Conc.IO(ensureIOManagerIsRunning,ioManagerCapabilitiesChanged-- * Waiting,threadDelay,registerDelay,threadWaitRead,threadWaitWrite,threadWaitReadSTM,threadWaitWriteSTM,closeFdWith#if defined(mingw32_HOST_OS),asyncRead,asyncWrite,asyncDoProc,asyncReadBA,asyncWriteBA,ConsoleEvent(..),win32ConsoleHandler,toWin32ConsoleEvent#endif)whereimportForeignimportGHC.BaseimportGHC.Conc.SyncasSyncimportGHC.Real(fromIntegral)importSystem.Posix.Types#if defined(mingw32_HOST_OS)importqualifiedGHC.Conc.WindowsasWindowsimportGHC.Conc.Windows(asyncRead,asyncWrite,asyncDoProc,asyncReadBA,asyncWriteBA,ConsoleEvent(..),win32ConsoleHandler,toWin32ConsoleEvent)#elseimportqualifiedGHC.Event.ThreadasEvent#endifensureIOManagerIsRunning::IO()#if !defined(mingw32_HOST_OS)ensureIOManagerIsRunning=Event.ensureIOManagerIsRunning#elseensureIOManagerIsRunning=Windows.ensureIOManagerIsRunning#endifioManagerCapabilitiesChanged::IO()#if !defined(mingw32_HOST_OS)ioManagerCapabilitiesChanged=Event.ioManagerCapabilitiesChanged#elseioManagerCapabilitiesChanged=return()#endif-- | 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()threadWaitReadfd#if !defined(mingw32_HOST_OS)|threaded=Event.threadWaitReadfd#endif|otherwise=IO$\s->casefromIntegralfdof{I#fd#->casewaitRead#fd#sof{s'->(#s',()#)}}-- | Block the current thread until data can be written to 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 'threadWaitWrite', use 'closeFdWith'.threadWaitWrite::Fd->IO()threadWaitWritefd#if !defined(mingw32_HOST_OS)|threaded=Event.threadWaitWritefd#endif|otherwise=IO$\s->casefromIntegralfdof{I#fd#->casewaitWrite#fd#sof{s'->(#s',()#)}}-- | Returns an STM action that can be used to wait for data-- to read from a file descriptor. The second returned value-- is an IO action that can be used to deregister interest-- in the file descriptor.threadWaitReadSTM::Fd->IO(Sync.STM(),IO())threadWaitReadSTMfd#if !defined(mingw32_HOST_OS)|threaded=Event.threadWaitReadSTMfd#endif|otherwise=dom<-Sync.newTVarIOFalset<-Sync.forkIO$dothreadWaitReadfdSync.atomically$Sync.writeTVarmTrueletwaitAction=dob<-Sync.readTVarmifbthenreturn()elseretryletkillAction=Sync.killThreadtreturn(waitAction,killAction)-- | Returns an STM action that can be used to wait until data-- can be written to a file descriptor. The second returned value-- is an IO action that can be used to deregister interest-- in the file descriptor.threadWaitWriteSTM::Fd->IO(Sync.STM(),IO())threadWaitWriteSTMfd#if !defined(mingw32_HOST_OS)|threaded=Event.threadWaitWriteSTMfd#endif|otherwise=dom<-Sync.newTVarIOFalset<-Sync.forkIO$dothreadWaitWritefdSync.atomically$Sync.writeTVarmTrueletwaitAction=dob<-Sync.readTVarmifbthenreturn()elseretryletkillAction=Sync.killThreadtreturn(waitAction,killAction)-- | 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.closeFdWith::(Fd->IO())-- ^ Low-level action that performs the real close.->Fd-- ^ File descriptor to close.->IO()closeFdWithclosefd#if !defined(mingw32_HOST_OS)|threaded=Event.closeFdWithclosefd#endif|otherwise=closefd-- | Suspends the current thread for a given number of microseconds-- (GHC only).---- There is no guarantee that the thread will be rescheduled promptly-- when the delay has expired, but the thread will never continue to-- run /earlier/ than specified.--threadDelay::Int->IO()threadDelaytime#if defined(mingw32_HOST_OS)|threaded=Windows.threadDelaytime#else|threaded=Event.threadDelaytime#endif|otherwise=IO$\s->casetimeof{I#time#->casedelay#time#sof{s'->(#s',()#)}}-- | Switch the value of returned 'TVar' from initial value 'False' to 'True'-- after a given number of microseconds. The caveats associated with-- 'threadDelay' also apply.--registerDelay::Int->IO(TVarBool)registerDelayusecs#if defined(mingw32_HOST_OS)|threaded=Windows.registerDelayusecs#else|threaded=Event.registerDelayusecs#endif|otherwise=errorWithoutStackTrace"registerDelay: requires -threaded"foreignimportccallunsafe"rtsSupportsBoundThreads"threaded::Bool
[8]ページ先頭