From f87771092c5df9e9c07bcb5052e662bde0a0fa59 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 4 Sep 2018 20:43:37 +0300 Subject: switch to rayon threadpool --- crates/server/src/lib.rs | 2 +- crates/server/src/main_loop/mod.rs | 14 ++++++++------ 2 files changed, 9 insertions(+), 7 deletions(-) (limited to 'crates/server/src') diff --git a/crates/server/src/lib.rs b/crates/server/src/lib.rs index d874ecf84..9e094af10 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 52e3b661d..52f2a8977 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) => { -- cgit v1.2.3