diff options
author | Aleksey Kladov <[email protected]> | 2018-09-04 18:43:37 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2018-09-04 18:43:37 +0100 |
commit | f87771092c5df9e9c07bcb5052e662bde0a0fa59 (patch) | |
tree | 9fd40d50ea64054dfc386b747e32479950df9f9d /crates/server/src/main_loop | |
parent | 8b0210d23367efecbf6e8ee9f19f372ff7d4fad3 (diff) |
switch to rayon threadpool
Diffstat (limited to 'crates/server/src/main_loop')
-rw-r--r-- | crates/server/src/main_loop/mod.rs | 14 |
1 files changed, 8 insertions, 6 deletions
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::{ | |||
6 | collections::{HashMap}, | 6 | collections::{HashMap}, |
7 | }; | 7 | }; |
8 | 8 | ||
9 | use threadpool::ThreadPool; | ||
10 | use serde::{Serialize, de::DeserializeOwned}; | 9 | use serde::{Serialize, de::DeserializeOwned}; |
11 | use crossbeam_channel::{unbounded, Sender, Receiver}; | 10 | use crossbeam_channel::{unbounded, Sender, Receiver}; |
11 | use rayon::{self, ThreadPool}; | ||
12 | use languageserver_types::{NumberOrString}; | 12 | use languageserver_types::{NumberOrString}; |
13 | use libanalysis::{FileId, JobHandle, JobToken, LibraryData}; | 13 | use libanalysis::{FileId, JobHandle, JobToken, LibraryData}; |
14 | use gen_lsp_server::{ | 14 | use gen_lsp_server::{ |
@@ -37,7 +37,9 @@ pub fn main_loop( | |||
37 | msg_receriver: &mut Receiver<RawMessage>, | 37 | msg_receriver: &mut Receiver<RawMessage>, |
38 | msg_sender: &mut Sender<RawMessage>, | 38 | msg_sender: &mut Sender<RawMessage>, |
39 | ) -> Result<()> { | 39 | ) -> Result<()> { |
40 | let pool = ThreadPool::new(4); | 40 | let pool = rayon::ThreadPoolBuilder::new() |
41 | .num_threads(4).build() | ||
42 | .unwrap(); | ||
41 | let (task_sender, task_receiver) = unbounded::<Task>(); | 43 | let (task_sender, task_receiver) = unbounded::<Task>(); |
42 | let (fs_sender, fs_receiver, fs_watcher) = vfs::roots_loader(); | 44 | let (fs_sender, fs_receiver, fs_watcher) = vfs::roots_loader(); |
43 | let (ws_sender, ws_receiver, ws_watcher) = workspace_loader(); | 45 | let (ws_sender, ws_receiver, ws_watcher) = workspace_loader(); |
@@ -68,7 +70,7 @@ pub fn main_loop( | |||
68 | task_receiver.for_each(|task| on_task(task, msg_sender, &mut pending_requests)); | 70 | task_receiver.for_each(|task| on_task(task, msg_sender, &mut pending_requests)); |
69 | info!("...tasks have finished"); | 71 | info!("...tasks have finished"); |
70 | info!("joining threadpool..."); | 72 | info!("joining threadpool..."); |
71 | pool.join(); | 73 | drop(pool); |
72 | info!("...threadpool has finished"); | 74 | info!("...threadpool has finished"); |
73 | 75 | ||
74 | let fs_res = fs_watcher.stop(); | 76 | let fs_res = fs_watcher.stop(); |
@@ -136,7 +138,7 @@ fn main_loop_inner( | |||
136 | } else { | 138 | } else { |
137 | let files = state.events_to_files(events); | 139 | let files = state.events_to_files(events); |
138 | let sender = libdata_sender.clone(); | 140 | let sender = libdata_sender.clone(); |
139 | pool.execute(move || { | 141 | pool.spawn(move || { |
140 | let start = ::std::time::Instant::now(); | 142 | let start = ::std::time::Instant::now(); |
141 | info!("indexing {} ... ", root.display()); | 143 | info!("indexing {} ... ", root.display()); |
142 | let data = LibraryData::prepare(files); | 144 | let data = LibraryData::prepare(files); |
@@ -354,7 +356,7 @@ impl<'a> PoolDispatcher<'a> { | |||
354 | let (handle, token) = JobHandle::new(); | 356 | let (handle, token) = JobHandle::new(); |
355 | let world = self.world.snapshot(); | 357 | let world = self.world.snapshot(); |
356 | let sender = self.sender.clone(); | 358 | let sender = self.sender.clone(); |
357 | self.pool.execute(move || { | 359 | self.pool.spawn(move || { |
358 | let resp = match f(world, params, token) { | 360 | let resp = match f(world, params, token) { |
359 | Ok(resp) => RawResponse::ok::<R>(id, &resp), | 361 | Ok(resp) => RawResponse::ok::<R>(id, &resp), |
360 | Err(e) => RawResponse::err(id, ErrorCode::InternalError as i32, e.to_string()), | 362 | Err(e) => RawResponse::err(id, ErrorCode::InternalError as i32, e.to_string()), |
@@ -386,7 +388,7 @@ fn update_file_notifications_on_threadpool( | |||
386 | sender: Sender<Task>, | 388 | sender: Sender<Task>, |
387 | subscriptions: Vec<FileId>, | 389 | subscriptions: Vec<FileId>, |
388 | ) { | 390 | ) { |
389 | pool.execute(move || { | 391 | pool.spawn(move || { |
390 | for file_id in subscriptions { | 392 | for file_id in subscriptions { |
391 | match handlers::publish_diagnostics(world.clone(), file_id) { | 393 | match handlers::publish_diagnostics(world.clone(), file_id) { |
392 | Err(e) => { | 394 | Err(e) => { |