]> git.proxmox.com Git - rustc.git/blob - vendor/num_threads/src/linux.rs
New upstream version 1.70.0+dfsg2
[rustc.git] / vendor / num_threads / src / linux.rs
1 use std::fs;
2 use std::num::NonZeroUsize;
3
4 pub(crate) fn num_threads() -> Option<NonZeroUsize> {
5 fs::read_to_string("/proc/self/stat")
6 .ok()
7 .as_ref()
8 // Skip past the pid and (process name) fields
9 .and_then(|stat| stat.rsplit(')').next())
10 // 20th field, less the two we skipped
11 .and_then(|rstat| rstat.split_whitespace().nth(17))
12 .and_then(|num_threads| num_threads.parse::<usize>().ok())
13 .and_then(NonZeroUsize::new)
14 }