aboutsummaryrefslogtreecommitdiff
path: root/crates/server/src/thread_watcher.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/server/src/thread_watcher.rs')
-rw-r--r--crates/server/src/thread_watcher.rs10
1 files changed, 10 insertions, 0 deletions
diff --git a/crates/server/src/thread_watcher.rs b/crates/server/src/thread_watcher.rs
index 98bcdfd6c..74a0a58b7 100644
--- a/crates/server/src/thread_watcher.rs
+++ b/crates/server/src/thread_watcher.rs
@@ -1,4 +1,5 @@
1use std::thread; 1use std::thread;
2use crossbeam_channel::{bounded, unbounded, Sender, Receiver};
2use drop_bomb::DropBomb; 3use drop_bomb::DropBomb;
3use Result; 4use Result;
4 5
@@ -31,3 +32,12 @@ impl ThreadWatcher {
31 res 32 res
32 } 33 }
33} 34}
35
36/// Sets up worker channels in a deadlock-avoind way.
37/// If one sets both input and output buffers to a fixed size,
38/// a worker might get stuck.
39pub fn worker_chan<I, O>(buf: usize) -> ((Sender<I>, Receiver<O>), Receiver<I>, Sender<O>) {
40 let (input_sender, input_receiver) = bounded::<I>(buf);
41 let (output_sender, output_receiver) = unbounded::<O>();
42 ((input_sender, output_receiver), input_receiver, output_sender)
43}