summaryrefslogtreecommitdiffstats
path: root/vendor/num_threads/src/linux.rs
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/num_threads/src/linux.rs')
-rw-r--r--vendor/num_threads/src/linux.rs14
1 files changed, 14 insertions, 0 deletions
diff --git a/vendor/num_threads/src/linux.rs b/vendor/num_threads/src/linux.rs
new file mode 100644
index 000000000..641b6b129
--- /dev/null
+++ b/vendor/num_threads/src/linux.rs
@@ -0,0 +1,14 @@
+use std::fs;
+use std::num::NonZeroUsize;
+
+pub(crate) fn num_threads() -> Option<NonZeroUsize> {
+ fs::read_to_string("/proc/self/stat")
+ .ok()
+ .as_ref()
+ // Skip past the pid and (process name) fields
+ .and_then(|stat| stat.rsplit(')').next())
+ // 20th field, less the two we skipped
+ .and_then(|rstat| rstat.split_whitespace().nth(17))
+ .and_then(|num_threads| num_threads.parse::<usize>().ok())
+ .and_then(NonZeroUsize::new)
+}