Create a new `ConcurrentRunner` with threads spun up.
()
| 46 | impl ConcurrentRunner { |
| 47 | /// Create a new `ConcurrentRunner` with threads spun up. |
| 48 | pub fn new() -> Self { |
| 49 | let (request_tx, request_rx) = channel(); |
| 50 | let request_mutex = Arc::new(Mutex::new(request_rx)); |
| 51 | let (reply_tx, reply_rx) = channel(); |
| 52 | |
| 53 | heartbeat_thread(reply_tx.clone()); |
| 54 | |
| 55 | let num_threads = std::env::var("CRANELIFT_FILETESTS_THREADS") |
| 56 | .ok() |
| 57 | .map(|s| { |
| 58 | use std::str::FromStr; |
| 59 | let n = usize::from_str(&s).unwrap(); |
| 60 | assert!(n > 0); |
| 61 | n |
| 62 | }) |
| 63 | .unwrap_or_else(|| num_cpus::get()); |
| 64 | let handles = (0..num_threads) |
| 65 | .map(|num| worker_thread(num, request_mutex.clone(), reply_tx.clone())) |
| 66 | .collect(); |
| 67 | |
| 68 | Self { |
| 69 | request_tx: Some(request_tx), |
| 70 | reply_rx, |
| 71 | handles, |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | /// Shut down worker threads orderly. They will finish any queued jobs first. |
| 76 | pub fn shutdown(&mut self) { |
nothing calls this directly
no test coverage detected