Use multiple threads for Relm async tasks depending on system
This commit is contained in:
parent
5e5df5c401
commit
2014c83224
1 changed files with 10 additions and 2 deletions
12
src/main.rs
12
src/main.rs
|
|
@ -4,6 +4,9 @@ mod persist;
|
||||||
mod ui;
|
mod ui;
|
||||||
mod views;
|
mod views;
|
||||||
|
|
||||||
|
use std::cmp::max;
|
||||||
|
use std::thread;
|
||||||
|
|
||||||
use gtk4::gdk::Display;
|
use gtk4::gdk::Display;
|
||||||
use gtk4::gio::File;
|
use gtk4::gio::File;
|
||||||
use gtk4::{CssProvider, Settings, gio};
|
use gtk4::{CssProvider, Settings, gio};
|
||||||
|
|
@ -18,8 +21,13 @@ fn main() {
|
||||||
|
|
||||||
include_app_css();
|
include_app_css();
|
||||||
|
|
||||||
// TODO: Set this to nr of cores if using Relm commands heavily.
|
// Set number of threads used by Relm for async tasks to the number of available
|
||||||
// RELM_THREADS.set(4).unwrap();
|
// CPU cores minus two, thereby reserving one for the main thread and one for
|
||||||
|
// the database connection thread spawned by async_sqlite.
|
||||||
|
let cores = thread::available_parallelism()
|
||||||
|
.map(|cores| cores.get() - 2)
|
||||||
|
.unwrap_or(1);
|
||||||
|
relm4::RELM_THREADS.set(max(cores, 1)).unwrap();
|
||||||
|
|
||||||
app.run::<App>(());
|
app.run::<App>(());
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue