From 13100da7a2aa97cdbda9ed4bd99896e2ff6d5cf6 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 9 Dec 2018 13:13:36 +0300 Subject: switch threadpool back from rayon to threadpool rayon does not replenish the pool when the thread panics, but we must be reselient to bugs. --- crates/ra_lsp_server/Cargo.toml | 1 + crates/ra_lsp_server/src/main_loop.rs | 15 ++++++--------- 2 files changed, 7 insertions(+), 9 deletions(-) (limited to 'crates/ra_lsp_server') diff --git a/crates/ra_lsp_server/Cargo.toml b/crates/ra_lsp_server/Cargo.toml index 79d86f9b2..5ee218b6b 100644 --- a/crates/ra_lsp_server/Cargo.toml +++ b/crates/ra_lsp_server/Cargo.toml @@ -6,6 +6,7 @@ authors = ["Aleksey Kladov "] [dependencies] rayon = "1.0.2" +threadpool = "1.7.1" relative-path = "0.4.0" failure = "0.1.2" failure_derive = "0.1.2" diff --git a/crates/ra_lsp_server/src/main_loop.rs b/crates/ra_lsp_server/src/main_loop.rs index 0e1878906..a01eeff88 100644 --- a/crates/ra_lsp_server/src/main_loop.rs +++ b/crates/ra_lsp_server/src/main_loop.rs @@ -9,7 +9,8 @@ use gen_lsp_server::{ }; use languageserver_types::NumberOrString; use ra_analysis::{Canceled, FileId, LibraryData}; -use rayon::{self, ThreadPool}; +use rayon; +use threadpool::ThreadPool; use rustc_hash::FxHashSet; use serde::{de::DeserializeOwned, Serialize}; use failure::{format_err, bail}; @@ -54,11 +55,7 @@ pub fn main_loop( msg_receiver: &Receiver, msg_sender: &Sender, ) -> Result<()> { - let pool = rayon::ThreadPoolBuilder::new() - .num_threads(4) - .panic_handler(|_| log::error!("thread panicked :(")) - .build() - .unwrap(); + let pool = ThreadPool::new(8); let (task_sender, task_receiver) = unbounded::(); let (fs_worker, fs_watcher) = vfs::roots_loader(); let (ws_worker, ws_watcher) = workspace_loader(); @@ -155,7 +152,7 @@ fn main_loop_inner( } else { let (files, resolver) = state.events_to_files(events); let sender = libdata_sender.clone(); - pool.spawn(move || { + pool.execute(move || { let start = ::std::time::Instant::now(); log::info!("indexing {} ... ", root.display()); let data = LibraryData::prepare(files, resolver); @@ -402,7 +399,7 @@ impl<'a> PoolDispatcher<'a> { Ok((id, params)) => { let world = self.world.snapshot(); let sender = self.sender.clone(); - self.pool.spawn(move || { + self.pool.execute(move || { let resp = match f(world, params) { Ok(resp) => RawResponse::ok::(id, &resp), Err(e) => match e.downcast::() { @@ -452,7 +449,7 @@ fn update_file_notifications_on_threadpool( sender: Sender, subscriptions: Vec, ) { - pool.spawn(move || { + pool.execute(move || { for file_id in subscriptions { match handlers::publish_diagnostics(&world, file_id) { Err(e) => { -- cgit v1.2.3