2019-09-12 11:39:39 -07:00
|
|
|
#[macro_use]
|
|
|
|
extern crate lazy_static;
|
|
|
|
|
|
|
|
use std::sync::RwLock;
|
|
|
|
|
|
|
|
//TODO remove this hack when rayon fixes itself
|
2019-09-18 18:00:07 -07:00
|
|
|
|
2019-09-12 11:39:39 -07:00
|
|
|
lazy_static! {
|
2019-09-18 18:00:07 -07:00
|
|
|
// reduce the number of threads each pool is allowed to half the cpu core count, to avoid rayon
|
|
|
|
// hogging cpu
|
2019-09-12 11:39:39 -07:00
|
|
|
static ref MAX_RAYON_THREADS: RwLock<usize> =
|
2019-09-18 18:00:07 -07:00
|
|
|
RwLock::new(sys_info::cpu_num().unwrap() as usize / 2);
|
2019-09-12 11:39:39 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn get_thread_count() -> usize {
|
|
|
|
*MAX_RAYON_THREADS.read().unwrap()
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn set_thread_count(count: usize) {
|
|
|
|
*MAX_RAYON_THREADS.write().unwrap() = count;
|
|
|
|
}
|