Skip to content

Commit

Permalink
Use GHC.Conc.Sync.getNumProcessors instead of C (#8590)
Browse files Browse the repository at this point in the history
The C call is almost exactly the same as GHC.Conc.Sync.getNumProcessors,
and we used the C function from GHC, so there should be no actual
difference.
  • Loading branch information
fgaz authored and alexbiehl committed Dec 15, 2022
1 parent 833b78a commit 3067a87
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions cabal-install/src/Distribution/Client/Utils.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{-# LANGUAGE ForeignFunctionInterface, ScopedTypeVariables, CPP #-}
{-# LANGUAGE ScopedTypeVariables, CPP #-}

module Distribution.Client.Utils
( MergeResult(..)
Expand Down Expand Up @@ -48,7 +48,6 @@ import Control.Monad
( zipWithM_ )
import Data.List
( groupBy )
import Foreign.C.Types ( CInt(..) )
import qualified Control.Exception as Exception
( finally )
import qualified Control.Exception.Safe as Safe
Expand All @@ -62,6 +61,7 @@ import System.IO
)
import System.IO.Unsafe ( unsafePerformIO )

import GHC.Conc.Sync ( getNumProcessors )
import GHC.IO.Encoding
( recover, TextEncoding(TextEncoding) )
import GHC.IO.Encoding.Failure
Expand Down Expand Up @@ -196,12 +196,10 @@ logDirChange l (Just d) m = do
m `Exception.finally`
(l $ "cabal: Leaving directory '" ++ d ++ "'\n")

foreign import ccall "getNumberOfProcessors" c_getNumberOfProcessors :: IO CInt

-- The number of processors is not going to change during the duration of the
-- program, so unsafePerformIO is safe here.
numberOfProcessors :: Int
numberOfProcessors = fromEnum $ unsafePerformIO c_getNumberOfProcessors
numberOfProcessors = unsafePerformIO getNumProcessors

-- | Determine the number of jobs to use given the value of the '-j' flag.
determineNumJobs :: Flag (Maybe Int) -> Int
Expand Down

0 comments on commit 3067a87

Please sign in to comment.