| 1 | //! Minimum supported Rust version: 1.28 |
| 2 | |
| 3 | use std::num::NonZeroUsize; |
| 4 | |
| 5 | #[cfg_attr(any(target_os = "linux", target_os = "android"), path = "linux.rs")] |
| 6 | #[cfg_attr(target_os = "freebsd", path = "freebsd.rs")] |
| 7 | #[cfg_attr(any(target_os = "macos", target_os = "ios"), path = "apple.rs")] |
| 8 | #[cfg_attr(target_os = "aix", path = "aix.rs")] |
| 9 | mod imp; |
| 10 | |
| 11 | /// Obtain the number of threads currently part of the active process. Returns `None` if the number |
| 12 | /// of threads cannot be determined. |
| 13 | pub fn num_threads() -> Option<NonZeroUsize> { |
| 14 | imp::num_threads() |
| 15 | } |
| 16 | |
| 17 | /// Determine if the current process is single-threaded. Returns `None` if the number of threads |
| 18 | /// cannot be determined. |
| 19 | pub fn is_single_threaded() -> Option<bool> { |
| 20 | num_threads().map(|n| n.get() == 1) |
| 21 | } |