1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#![doc(html_root_url = "https://docs.rs/executors/0.4.4")]
#![allow(unused_parens)]
#[macro_use]
extern crate log;
pub mod common;
pub mod bichannel;
pub mod run_now;
#[cfg(feature = "cb-channel-exec")]
pub mod crossbeam_channel_pool;
#[cfg(feature = "workstealing-exec")]
pub mod crossbeam_workstealing_pool;
#[cfg(feature = "threadpool-exec")]
pub mod threadpool_executor;
mod timeconstants;
pub use crate::common::Executor;
use crate::common::ignore;
use synchronoise::CountdownEvent;
#[cfg(test)]
pub(crate) mod tests {
use super::*;
use std::sync::Arc;
use std::time::Duration;
pub const N_DEPTH: usize = 32;
pub const N_WIDTH: usize = 8;
pub fn test_debug<E>(exec: &E, label: &str) where E: Executor+std::fmt::Debug {
println!("Debug output for {}: {:?}", label, exec);
}
pub fn test_defaults<E>(label: &str) where E: Executor+std::default::Default+'static {
let pool = E::default();
let latch = Arc::new(CountdownEvent::new(N_DEPTH * N_WIDTH));
for _ in 0..N_WIDTH {
let pool2 = pool.clone();
let latch2 = latch.clone();
pool.execute(move || {
do_step(latch2, pool2, N_DEPTH);
});
}
let res = latch.wait_timeout(Duration::from_secs(5));
assert_eq!(res, 0);
pool.shutdown().unwrap_or_else(|e| error!("Error during pool shutdown {:?} at {}",e, label));
}
fn do_step<E>(latch: Arc<CountdownEvent>, pool: E, depth: usize) where E: Executor+'static {
let new_depth = depth - 1;
ignore(latch.decrement());
if (new_depth > 0) {
let pool2 = pool.clone();
pool.execute(move || {do_step(latch, pool2, new_depth)})
}
}
}