diff --git a/crates/server/Cargo.toml b/crates/server/Cargo.toml index cb96929c60..9aeea9a9b1 100644 --- a/crates/server/Cargo.toml +++ b/crates/server/Cargo.toml @@ -4,6 +4,7 @@ version = "0.1.0" authors = ["Aleksey Kladov "] [dependencies] +rayon = "1.0.2" relative-path = "0.3.7" failure = "0.1.2" serde_json = "1.0.24" @@ -11,7 +12,6 @@ serde = "1.0.71" serde_derive = "1.0.71" drop_bomb = "0.1.0" crossbeam-channel = "0.2.4" -threadpool = "1.7.1" flexi_logger = "0.9.1" log = "0.4.3" url_serde = "0.2.0" diff --git a/crates/server/src/lib.rs b/crates/server/src/lib.rs index d874ecf847..9e094af109 100644 --- a/crates/server/src/lib.rs +++ b/crates/server/src/lib.rs @@ -7,7 +7,7 @@ extern crate serde_json; extern crate languageserver_types; #[macro_use] extern crate crossbeam_channel; -extern crate threadpool; +extern crate rayon; #[macro_use] extern crate log; extern crate drop_bomb; diff --git a/crates/server/src/main_loop/mod.rs b/crates/server/src/main_loop/mod.rs index 52e3b661d7..52f2a89775 100644 --- a/crates/server/src/main_loop/mod.rs +++ b/crates/server/src/main_loop/mod.rs @@ -6,9 +6,9 @@ use std::{ collections::{HashMap}, }; -use threadpool::ThreadPool; use serde::{Serialize, de::DeserializeOwned}; use crossbeam_channel::{unbounded, Sender, Receiver}; +use rayon::{self, ThreadPool}; use languageserver_types::{NumberOrString}; use libanalysis::{FileId, JobHandle, JobToken, LibraryData}; use gen_lsp_server::{ @@ -37,7 +37,9 @@ pub fn main_loop( msg_receriver: &mut Receiver, msg_sender: &mut Sender, ) -> Result<()> { - let pool = ThreadPool::new(4); + let pool = rayon::ThreadPoolBuilder::new() + .num_threads(4).build() + .unwrap(); let (task_sender, task_receiver) = unbounded::(); let (fs_sender, fs_receiver, fs_watcher) = vfs::roots_loader(); let (ws_sender, ws_receiver, ws_watcher) = workspace_loader(); @@ -68,7 +70,7 @@ pub fn main_loop( task_receiver.for_each(|task| on_task(task, msg_sender, &mut pending_requests)); info!("...tasks have finished"); info!("joining threadpool..."); - pool.join(); + drop(pool); info!("...threadpool has finished"); let fs_res = fs_watcher.stop(); @@ -136,7 +138,7 @@ fn main_loop_inner( } else { let files = state.events_to_files(events); let sender = libdata_sender.clone(); - pool.execute(move || { + pool.spawn(move || { let start = ::std::time::Instant::now(); info!("indexing {} ... ", root.display()); let data = LibraryData::prepare(files); @@ -354,7 +356,7 @@ impl<'a> PoolDispatcher<'a> { let (handle, token) = JobHandle::new(); let world = self.world.snapshot(); let sender = self.sender.clone(); - self.pool.execute(move || { + self.pool.spawn(move || { let resp = match f(world, params, token) { Ok(resp) => RawResponse::ok::(id, &resp), Err(e) => RawResponse::err(id, ErrorCode::InternalError as i32, e.to_string()), @@ -386,7 +388,7 @@ fn update_file_notifications_on_threadpool( sender: Sender, subscriptions: Vec, ) { - pool.execute(move || { + pool.spawn(move || { for file_id in subscriptions { match handlers::publish_diagnostics(world.clone(), file_id) { Err(e) => {