Skip to content

Commit

Permalink
Merge pull request #5 from well-typed/jdral/threaded-rts-check
Browse files Browse the repository at this point in the history
Throw an error in `initIOCtx` if the RTS is not threaded
  • Loading branch information
dcoutts authored Mar 7, 2024
2 parents f483f95 + a6ec7ab commit 3d3ca38
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions System/IO/BlockIO.hs
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,15 @@ import Control.Concurrent.MVar
import Control.Concurrent.QSemN
import Control.Concurrent.Chan
import Control.Exception (mask_, throw, ArrayException(UndefinedElement),
finally, assert)
finally, assert, throwIO)
import System.IO.Error
import GHC.IO.Exception (IOErrorType(ResourceVanished))

import Foreign.Ptr
import Foreign.C.Error (Errno(..))
import Foreign.C.Types (CInt(..), CSize)
import System.Posix.Types (Fd, FileOffset, ByteCount)
import System.Posix.Internals (hostIsThreaded)

import qualified System.IO.BlockIO.URing as URing

Expand Down Expand Up @@ -92,7 +93,8 @@ defaultIOCtxParams =
}

initIOCtx :: IOCtxParams -> IO IOCtx
initIOCtx IOCtxParams {ioctxBatchSizeLimit, ioctxConcurrencyLimit} =
initIOCtx IOCtxParams {ioctxBatchSizeLimit, ioctxConcurrencyLimit} = do
unless hostIsThreaded $ throwIO rtrsNotThreaded
mask_ $ do
ioctxQSemN <- newQSemN ioctxConcurrencyLimit
uring <- URing.setupURing (URing.URingParams ioctxBatchSizeLimit)
Expand All @@ -119,6 +121,13 @@ initIOCtx IOCtxParams {ioctxBatchSizeLimit, ioctxConcurrencyLimit} =
ioctxChanIOBatchIx,
ioctxCloseSync
}
where
rtrsNotThreaded =
mkIOError
illegalOperationErrorType
"The run-time system should be threaded, make sure you are passing the -threaded flag"
Nothing
Nothing

closeIOCtx :: IOCtx -> IO ()
closeIOCtx IOCtx {ioctxURing, ioctxCloseSync} = do
Expand Down

0 comments on commit 3d3ca38

Please sign in to comment.