Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Jan 2, 2021. It is now read-only.

Commit 256f8b5

Browse files
committed
Attempt to fix logic to only allow one cradle to be running at once.
1 parent 26c98ca commit 256f8b5

2 files changed

Lines changed: 29 additions & 6 deletions

File tree

exe/Main.hs

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ import Data.Either
6262
import qualified Crypto.Hash.SHA1 as H
6363
import qualified Data.ByteString.Char8 as B
6464
import Data.ByteString.Base16 (encode)
65+
import Control.Concurrent.Async
6566

6667
import DynFlags (gopt_set, gopt_unset,
6768
updOptLevel)
@@ -346,7 +347,6 @@ loadSession dir = liftIO $ do
346347
return res
347348

348349
lock <- newLock
349-
cradle_lock <- newLock
350350

351351
-- This caches the mapping from hie.yaml + Mod.hs -> [String]
352352
sessionOpts <- return $ \(hieYaml, file) -> do
@@ -373,17 +373,39 @@ loadSession dir = liftIO $ do
373373
finished_barrier <- newBarrier
374374
-- fork a new thread here which won't be killed by shake
375375
-- throwing an async exception
376-
void $ forkIO $ withLock cradle_lock $ do
377-
putStrLn $ "Shelling out to cabal " <> show file
376+
void $ forkIO $ do
377+
putStrLn $ "Consulting the cradle for " <> show file
378378
cradle <- maybe (loadImplicitCradle $ addTrailingPathSeparator dir) loadCradle hieYaml
379379
opts <- cradleToSessionOpts cradle cfp
380380
print opts
381381
res <- fst <$> session (hieYaml, toNormalizedFilePath' cfp, opts)
382382
signalBarrier finished_barrier res
383383
waitBarrier finished_barrier
384-
return $ \file -> liftIO $ mask_ $ withLock lock $ do
385-
hieYaml <- cradleLoc file
386-
sessionOpts (hieYaml, file)
384+
385+
dummyAs <- async $ return (error "Uninitialised")
386+
runningCradle <- newIORef dummyAs
387+
-- The main function which gets options for a file. We only want one of these running
388+
-- at a time.
389+
let getOptions file = do
390+
hieYaml <- cradleLoc file
391+
sessionOpts (hieYaml, file)
392+
-- The lock is on the `runningCradle` resource
393+
return $ \file -> liftIO $ withLock lock $ do
394+
as <- readIORef runningCradle
395+
finished <- poll as
396+
case finished of
397+
Just {} -> do
398+
as <- async $ getOptions file
399+
writeIORef runningCradle as
400+
wait as
401+
-- If it's not finished then wait and then get options, this could of course be killed still
402+
Nothing -> do
403+
_ <- wait as
404+
getOptions file
405+
406+
407+
408+
387409

388410
checkDependencyInfo :: Map.Map FilePath (Maybe UTCTime) -> IO Bool
389411
checkDependencyInfo old_di = do

ghcide.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ executable ghcide
176176
main-is: Main.hs
177177
build-depends:
178178
time,
179+
async,
179180
hslogger,
180181
aeson,
181182
base == 4.*,

0 commit comments

Comments
 (0)