2021-12-18 22:59:55 +00:00
|
|
|
#![doc = include_str!("../README.md")]
|
|
|
|
|
2020-08-29 19:35:41 +00:00
|
|
|
mod slice;
|
|
|
|
pub use slice::{ParallelSlice, ParallelSliceMut};
|
|
|
|
|
|
|
|
mod task;
|
|
|
|
pub use task::Task;
|
|
|
|
|
2023-07-09 04:22:15 +00:00
|
|
|
#[cfg(all(not(target_arch = "wasm32"), feature = "multi-threaded"))]
|
2020-08-29 19:35:41 +00:00
|
|
|
mod task_pool;
|
2023-07-09 04:22:15 +00:00
|
|
|
#[cfg(all(not(target_arch = "wasm32"), feature = "multi-threaded"))]
|
2020-08-29 19:35:41 +00:00
|
|
|
pub use task_pool::{Scope, TaskPool, TaskPoolBuilder};
|
|
|
|
|
2023-07-09 04:22:15 +00:00
|
|
|
#[cfg(any(target_arch = "wasm32", not(feature = "multi-threaded")))]
|
2020-09-16 01:05:31 +00:00
|
|
|
mod single_threaded_task_pool;
|
2023-07-09 04:22:15 +00:00
|
|
|
#[cfg(any(target_arch = "wasm32", not(feature = "multi-threaded")))]
|
2023-11-15 14:29:43 +00:00
|
|
|
pub use single_threaded_task_pool::{FakeTask, Scope, TaskPool, TaskPoolBuilder, ThreadExecutor};
|
2020-09-16 01:05:31 +00:00
|
|
|
|
2020-08-29 19:35:41 +00:00
|
|
|
mod usages;
|
2022-10-24 13:46:40 +00:00
|
|
|
#[cfg(not(target_arch = "wasm32"))]
|
|
|
|
pub use usages::tick_global_task_pools_on_main_thread;
|
2020-09-22 03:23:09 +00:00
|
|
|
pub use usages::{AsyncComputeTaskPool, ComputeTaskPool, IoTaskPool};
|
2020-08-29 19:35:41 +00:00
|
|
|
|
2023-08-03 07:47:09 +00:00
|
|
|
#[cfg(all(not(target_arch = "wasm32"), feature = "multi-threaded"))]
|
2023-01-10 22:32:42 +00:00
|
|
|
mod thread_executor;
|
2023-08-03 07:47:09 +00:00
|
|
|
#[cfg(all(not(target_arch = "wasm32"), feature = "multi-threaded"))]
|
2023-01-10 22:32:42 +00:00
|
|
|
pub use thread_executor::{ThreadExecutor, ThreadExecutorTicker};
|
|
|
|
|
2023-09-25 19:59:50 +00:00
|
|
|
#[cfg(feature = "async-io")]
|
|
|
|
pub use async_io::block_on;
|
|
|
|
#[cfg(not(feature = "async-io"))]
|
|
|
|
pub use futures_lite::future::block_on;
|
|
|
|
|
2020-09-08 19:18:32 +00:00
|
|
|
mod iter;
|
|
|
|
pub use iter::ParallelIterator;
|
|
|
|
|
2023-11-21 16:51:13 +00:00
|
|
|
pub use futures_lite;
|
|
|
|
|
2022-01-16 04:53:22 +00:00
|
|
|
#[allow(missing_docs)]
|
2020-08-29 19:35:41 +00:00
|
|
|
pub mod prelude {
|
2022-11-02 20:40:45 +00:00
|
|
|
#[doc(hidden)]
|
2020-08-29 19:35:41 +00:00
|
|
|
pub use crate::{
|
2023-09-25 19:59:50 +00:00
|
|
|
block_on,
|
2020-09-08 19:18:32 +00:00
|
|
|
iter::ParallelIterator,
|
2020-08-29 19:35:41 +00:00
|
|
|
slice::{ParallelSlice, ParallelSliceMut},
|
2020-09-22 03:23:09 +00:00
|
|
|
usages::{AsyncComputeTaskPool, ComputeTaskPool, IoTaskPool},
|
2020-08-29 19:35:41 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-09-19 15:46:03 +00:00
|
|
|
use std::num::NonZeroUsize;
|
|
|
|
|
|
|
|
/// Gets the logical CPU core count available to the current process.
|
|
|
|
///
|
|
|
|
/// This is identical to [`std::thread::available_parallelism`], except
|
|
|
|
/// it will return a default value of 1 if it internally errors out.
|
|
|
|
///
|
|
|
|
/// This will always return at least 1.
|
|
|
|
pub fn available_parallelism() -> usize {
|
|
|
|
std::thread::available_parallelism()
|
|
|
|
.map(NonZeroUsize::get)
|
|
|
|
.unwrap_or(1)
|
|
|
|
}
|