summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--.github/workflows/rust-unused-dependencies.yml2
-rw-r--r--mullvad-daemon/src/runtime.rs15
2 files changed, 15 insertions, 2 deletions
diff --git a/.github/workflows/rust-unused-dependencies.yml b/.github/workflows/rust-unused-dependencies.yml
index 47c58bcca2..d00c9b5c26 100644
--- a/.github/workflows/rust-unused-dependencies.yml
+++ b/.github/workflows/rust-unused-dependencies.yml
@@ -10,7 +10,7 @@ on:
workflow_dispatch:
env:
# Pinning nightly just to avoid random breakage. It's fine to bump this at any time
- RUST_NIGHTLY_TOOLCHAIN: nightly-2024-10-02
+ RUST_NIGHTLY_TOOLCHAIN: nightly-2025-05-14
permissions: {}
diff --git a/mullvad-daemon/src/runtime.rs b/mullvad-daemon/src/runtime.rs
index 86d251db4c..5f4521ed01 100644
--- a/mullvad-daemon/src/runtime.rs
+++ b/mullvad-daemon/src/runtime.rs
@@ -1,8 +1,21 @@
+use std::num::NonZero;
use tokio::runtime;
+const MIN_NUM_THREADS: NonZero<usize> = NonZero::new(4).unwrap();
+
pub fn new_multi_thread() -> runtime::Builder {
let mut builder = runtime::Builder::new_multi_thread();
- builder.worker_threads(4).enable_all();
+ match std::thread::available_parallelism() {
+ Ok(num_cpus) if num_cpus < MIN_NUM_THREADS => {
+ builder.worker_threads(MIN_NUM_THREADS.into());
+ }
+ // Use default number of workers
+ Ok(_) => (),
+ Err(error) => {
+ log::warn!("Failed to retrieve number of CPU cores: {error}");
+ }
+ }
+ builder.enable_all();
builder
}