-
-
Notifications
You must be signed in to change notification settings - Fork 391
Unify critical session running in hls #4256
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 31 commits
Commits
Show all changes
38 commits
Select commit
Hold shift + click to select a range
15f9892
add thread to do shake restart
soulomoon 3ba47f6
fix
soulomoon 5d66041
run session loader in thread
soulomoon d7946a0
fix 9.2
soulomoon da56bfb
rename
soulomoon fb0a370
use evalContT
soulomoon d1775e6
add doc
soulomoon 39bdf6a
fix doc
soulomoon b06186b
fix import
soulomoon 1a9374b
export explicit
soulomoon c9bdc87
add comment
soulomoon cb131e3
cleanup
soulomoon 96d6d07
cleanup
soulomoon b552c80
fix note
soulomoon aef173a
add `blockRunInThread`
soulomoon f231648
Merge branch 'master' into soulomoon/add-threads
soulomoon d08f175
fix
soulomoon 60839b0
fix 9.2 import
soulomoon aba6a88
Merge branch 'master' into soulomoon/add-threads
soulomoon 981724e
Merge branch 'master' into soulomoon/add-threads
soulomoon 8f9ef7a
Merge branch 'master' into soulomoon/add-threads
soulomoon 0e3a6e8
Merge branch 'master' into soulomoon/add-threads
soulomoon a1b0a69
Merge branch 'master' into soulomoon/add-threads
soulomoon 78e9fc1
Merge branch 'master' into soulomoon/add-threads
soulomoon b2be89f
Update ghcide/src/Development/IDE/Core/Thread.hs
soulomoon 8aea82e
refactor to withWorkerQueue
soulomoon 8c3773f
typo
soulomoon 5f27fad
ident
soulomoon e800cac
Improve Note
soulomoon 86d7fb9
add comment
soulomoon 027e5be
format
soulomoon 99322fa
Update WorkerThread.hs
soulomoon c1b3e7d
Update WorkerThread.hs
soulomoon a16d04a
rename to await
soulomoon c832da3
use block comment
soulomoon 6bdba37
merge
soulomoon 442e776
Remove duplicated comment
soulomoon 5d657b6
add file header comment
soulomoon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
module Development.IDE.Core.WorkerThread | ||
(withWorkerQueue, blockRunInThread) | ||
where | ||
|
||
import Control.Concurrent.Async | ||
import Control.Concurrent.STM | ||
import Control.Concurrent.Strict (newBarrier, signalBarrier, | ||
waitBarrier) | ||
import Control.Monad (forever) | ||
import Control.Monad.Cont (ContT (ContT)) | ||
|
||
-- Note [Serializing runs in separate thread] | ||
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
-- We often want to take long-running actions using some resource that cannot be shared. | ||
-- In this instance it is useful to have a queue of jobs to run using the resource. | ||
-- Like the db writes, session loading in session loader, shake session restarts. | ||
-- | ||
-- Originally we used various ways to implement this, but it was hard to maintain and error prone. | ||
-- Moreover, we can not stop these threads uniformly when we are shutting down the server. | ||
-- | ||
-- `Development.IDE.Core.WorkerThread` module provides a simple api to implement this easily. | ||
-- * `withWorkerQueue`: accepts an action to run in separate thread and returns a `TQueue` to send the actions to run. | ||
-- * `blockRunInThread` : accepts a `TQueue` and an action to run in separate thread and waits for the result. | ||
|
||
|
||
-- | withWorkerQueue creates a new TQueue and runs the workerAction in a separate thread. | ||
soulomoon marked this conversation as resolved.
Show resolved
Hide resolved
|
||
withWorkerQueue :: (t -> IO a) -> ContT () IO (TQueue t) | ||
withWorkerQueue workerAction = ContT $ \mainAction -> do | ||
q <- newTQueueIO | ||
withAsync (writerThread q) $ \_ -> mainAction q | ||
where | ||
writerThread q = | ||
forever $ do | ||
l <- atomically $ readTQueue q | ||
workerAction l | ||
|
||
-- | blockRunInThread run and wait for the result | ||
soulomoon marked this conversation as resolved.
Show resolved
Hide resolved
|
||
blockRunInThread :: TQueue (IO ()) -> IO result -> IO result | ||
soulomoon marked this conversation as resolved.
Show resolved
Hide resolved
|
||
blockRunInThread q act = do | ||
-- Take an action from TQueue, run it and | ||
-- use barrier to wait for the result | ||
barrier <- newBarrier | ||
atomically $ writeTQueue q $ do | ||
res <- act | ||
signalBarrier barrier res | ||
waitBarrier barrier |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.