aboutsummaryrefslogtreecommitdiff
path: root/crates/server/src/main_loop/mod.rs
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2018-09-08 11:15:01 +0100
committerAleksey Kladov <[email protected]>2018-09-08 11:15:01 +0100
commit7daaddb2ac281dcad3ac99496b1cf3f06840887d (patch)
tree3a6c9ac35c0f198c782591b50eb50225769955bb /crates/server/src/main_loop/mod.rs
parent326ffcefe09906560a03d3184a2ce76841448702 (diff)
Some abstraction around workers
Diffstat (limited to 'crates/server/src/main_loop/mod.rs')
-rw-r--r--crates/server/src/main_loop/mod.rs28
1 files changed, 12 insertions, 16 deletions
diff --git a/crates/server/src/main_loop/mod.rs b/crates/server/src/main_loop/mod.rs
index b7f5efbb1..f1297ee48 100644
--- a/crates/server/src/main_loop/mod.rs
+++ b/crates/server/src/main_loop/mod.rs
@@ -23,6 +23,7 @@ use {
23 server_world::{ServerWorldState, ServerWorld}, 23 server_world::{ServerWorldState, ServerWorld},
24 main_loop::subscriptions::{Subscriptions}, 24 main_loop::subscriptions::{Subscriptions},
25 project_model::{CargoWorkspace, workspace_loader}, 25 project_model::{CargoWorkspace, workspace_loader},
26 thread_watcher::Worker,
26}; 27};
27 28
28#[derive(Debug)] 29#[derive(Debug)]
@@ -43,8 +44,8 @@ pub fn main_loop(
43 .build() 44 .build()
44 .unwrap(); 45 .unwrap();
45 let (task_sender, task_receiver) = unbounded::<Task>(); 46 let (task_sender, task_receiver) = unbounded::<Task>();
46 let ((fs_sender, fs_receiver), fs_watcher) = vfs::roots_loader(); 47 let (fs_worker, fs_watcher) = vfs::roots_loader();
47 let ((ws_sender, ws_receiver), ws_watcher) = workspace_loader(); 48 let (ws_worker, ws_watcher) = workspace_loader();
48 49
49 info!("server initialized, serving requests"); 50 info!("server initialized, serving requests");
50 let mut state = ServerWorldState::new(); 51 let mut state = ServerWorldState::new();
@@ -59,10 +60,8 @@ pub fn main_loop(
59 msg_receriver, 60 msg_receriver,
60 task_sender, 61 task_sender,
61 task_receiver.clone(), 62 task_receiver.clone(),
62 fs_sender, 63 fs_worker,
63 fs_receiver, 64 ws_worker,
64 ws_sender,
65 ws_receiver,
66 &mut state, 65 &mut state,
67 &mut pending_requests, 66 &mut pending_requests,
68 &mut subs, 67 &mut subs,
@@ -93,17 +92,15 @@ fn main_loop_inner(
93 msg_receiver: &mut Receiver<RawMessage>, 92 msg_receiver: &mut Receiver<RawMessage>,
94 task_sender: Sender<Task>, 93 task_sender: Sender<Task>,
95 task_receiver: Receiver<Task>, 94 task_receiver: Receiver<Task>,
96 fs_sender: Sender<PathBuf>, 95 fs_worker: Worker<PathBuf, (PathBuf, Vec<FileEvent>)>,
97 fs_receiver: Receiver<(PathBuf, Vec<FileEvent>)>, 96 ws_worker: Worker<PathBuf, Result<CargoWorkspace>>,
98 ws_sender: Sender<PathBuf>,
99 ws_receiver: Receiver<Result<CargoWorkspace>>,
100 state: &mut ServerWorldState, 97 state: &mut ServerWorldState,
101 pending_requests: &mut HashMap<u64, JobHandle>, 98 pending_requests: &mut HashMap<u64, JobHandle>,
102 subs: &mut Subscriptions, 99 subs: &mut Subscriptions,
103) -> Result<()> { 100) -> Result<()> {
104 let (libdata_sender, libdata_receiver) = unbounded(); 101 let (libdata_sender, libdata_receiver) = unbounded();
105 ws_sender.send(ws_root.clone()); 102 ws_worker.send(ws_root.clone());
106 fs_sender.send(ws_root.clone()); 103 fs_worker.send(ws_root.clone());
107 loop { 104 loop {
108 #[derive(Debug)] 105 #[derive(Debug)]
109 enum Event { 106 enum Event {
@@ -120,11 +117,11 @@ fn main_loop_inner(
120 None => bail!("client exited without shutdown"), 117 None => bail!("client exited without shutdown"),
121 }, 118 },
122 recv(task_receiver, task) => Event::Task(task.unwrap()), 119 recv(task_receiver, task) => Event::Task(task.unwrap()),
123 recv(fs_receiver, events) => match events { 120 recv(fs_worker.out, events) => match events {
124 None => bail!("roots watcher died"), 121 None => bail!("roots watcher died"),
125 Some((pb, events)) => Event::Fs(pb, events), 122 Some((pb, events)) => Event::Fs(pb, events),
126 } 123 }
127 recv(ws_receiver, ws) => match ws { 124 recv(ws_worker.out, ws) => match ws {
128 None => bail!("workspace watcher died"), 125 None => bail!("workspace watcher died"),
129 Some(ws) => Event::Ws(ws), 126 Some(ws) => Event::Ws(ws),
130 } 127 }
@@ -158,8 +155,7 @@ fn main_loop_inner(
158 for ws in workspaces.iter() { 155 for ws in workspaces.iter() {
159 for pkg in ws.packages().filter(|pkg| !pkg.is_member(ws)) { 156 for pkg in ws.packages().filter(|pkg| !pkg.is_member(ws)) {
160 debug!("sending root, {}", pkg.root(ws).to_path_buf().display()); 157 debug!("sending root, {}", pkg.root(ws).to_path_buf().display());
161 // deadlocky :-( 158 fs_worker.send(pkg.root(ws).to_path_buf());
162 fs_sender.send(pkg.root(ws).to_path_buf());
163 } 159 }
164 } 160 }
165 state.set_workspaces(workspaces); 161 state.set_workspaces(workspaces);