mirror of
https://github.com/alexpasmantier/television.git
synced 2025-06-10 05:17:10 +00:00

The state of the UI is now synchronized with the `Television` struct using a dedicated channel and is available at `Television.ui_state`. This removes quite a bit of complexity from the existing code and should allow for nicer implementations of features that need the UI state to compute things in the background (typically knowing the target size of an image you wish to construct in the background, as in #363) The `UiState` currently only holds the UI layout: ```rs pub struct UiState { pub layout: Layout, } ```
19 lines
680 B
Rust
19 lines
680 B
Rust
use std::num::NonZeroUsize;
|
|
|
|
/// Get the number of threads to use by default.
|
|
///
|
|
/// This will use the number of available threads if possible, but will default to 1 if the number
|
|
/// of available threads cannot be determined. It will also never use more than 32 threads to avoid
|
|
/// startup overhead.
|
|
pub fn default_num_threads() -> usize {
|
|
// default to 1 thread if we can't determine the number of available threads
|
|
let default = NonZeroUsize::MIN;
|
|
// never use more than 32 threads to avoid startup overhead
|
|
let limit = NonZeroUsize::new(32).unwrap();
|
|
|
|
std::thread::available_parallelism()
|
|
.unwrap_or(default)
|
|
.min(limit)
|
|
.get()
|
|
}
|