Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make ThreadPool optional #1910

Merged
merged 1 commit into from
Oct 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ matrix:
- name: cargo build (minimum required version)
rust: 1.36.0
script:
# default features & compat feature
- cargo run --manifest-path ci/remove-dev-dependencies/Cargo.toml */Cargo.toml
# Check default-features
- cargo build --all
# Check compat & threadpool features
- cargo build --manifest-path futures/Cargo.toml --features io-compat
- cargo build --manifest-path futures/Cargo.toml --features threadpool

# This is the minimum Rust version supported by `async-await` feature.
# When updating this, the reminder to update the minimum required version of `async-await` feature in README.md.
Expand All @@ -31,18 +33,22 @@ matrix:
- name: cargo +stable build
rust: stable
script:
# default features & compat feature
- cargo run --manifest-path ci/remove-dev-dependencies/Cargo.toml */Cargo.toml
# Check default-features
- cargo build --all
# Check compat & threadpool features
- cargo build --manifest-path futures/Cargo.toml --features io-compat
- cargo build --manifest-path futures/Cargo.toml --features threadpool

- name: cargo +beta build
rust: beta
script:
# default features & compat feature & async-await feature
- cargo run --manifest-path ci/remove-dev-dependencies/Cargo.toml */Cargo.toml
# Check default-features
- cargo build --all
# Check compat & threadpool & async-await features
- cargo build --manifest-path futures/Cargo.toml --features io-compat
- cargo build --manifest-path futures/Cargo.toml --features threadpool
- cargo build --manifest-path futures/Cargo.toml --features async-await

- name: cargo test
Expand Down Expand Up @@ -169,7 +175,7 @@ matrix:
- cargo check --manifest-path futures-util/Cargo.toml --features io,bilock,unstable
- cargo check --manifest-path futures-util/Cargo.toml --features sink,io
- cargo check --manifest-path futures-util/Cargo.toml --features read_initializer,unstable

# Check each features with --no-default-features
- cargo check --manifest-path futures-util/Cargo.toml --no-default-features
- cargo check --manifest-path futures-util/Cargo.toml --no-default-features --features sink
- cargo check --manifest-path futures-util/Cargo.toml --no-default-features --features alloc,sink
Expand All @@ -178,6 +184,13 @@ matrix:
- cargo check --manifest-path futures-util/Cargo.toml --no-default-features --features sink,bilock,unstable
- cargo check --manifest-path futures-util/Cargo.toml --no-default-features --features io,bilock,unstable

# futures-executor
# Check default-features, all-features
- cargo check --manifest-path futures-executor/Cargo.toml
- cargo check --manifest-path futures-executor/Cargo.toml --all-features
# Check each features
- cargo check --manifest-path futures-executor/Cargo.toml --features threadpool

- name: cargo doc
rust: nightly
script:
Expand Down
3 changes: 2 additions & 1 deletion futures-executor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ name = "futures_executor"

[features]
default = ["std"]
std = ["futures-core-preview/std", "futures-util-preview/std", "num_cpus"]
std = ["futures-core-preview/std", "futures-util-preview/std"]
threadpool = ["num_cpus"]

[dependencies]
futures-core-preview = { path = "../futures-core", version = "=0.3.0-alpha.19", default-features = false }
Expand Down
3 changes: 3 additions & 0 deletions futures-executor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,13 @@ mod local_pool;
#[cfg(feature = "std")]
pub use crate::local_pool::{block_on, block_on_stream, BlockingStream, LocalPool, LocalSpawner};

#[cfg(feature = "threadpool")]
#[cfg(feature = "std")]
mod unpark_mutex;
#[cfg(feature = "threadpool")]
#[cfg(feature = "std")]
mod thread_pool;
#[cfg(feature = "threadpool")]
#[cfg(feature = "std")]
pub use crate::thread_pool::{ThreadPool, ThreadPoolBuilder};

Expand Down
6 changes: 6 additions & 0 deletions futures-executor/src/thread_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,17 @@ use std::thread;
///
/// This type is a clonable handle to the threadpool itself.
/// Cloning it will only create a new reference, not a new threadpool.
///
/// This type is only available when the `threadpool` feature of this
/// library is activated.
pub struct ThreadPool {
state: Arc<PoolState>,
}

/// Thread pool configuration object.
///
/// This type is only available when the `threadpool` feature of this
/// library is activated.
pub struct ThreadPoolBuilder {
pool_size: usize,
stack_size: usize,
Expand Down
1 change: 1 addition & 0 deletions futures/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ alloc = ["futures-core-preview/alloc", "futures-sink-preview/alloc", "futures-ch
async-await = ["futures-util-preview/async-await", "futures-util-preview/join-macro", "futures-util-preview/select-macro"]
compat = ["std", "futures-util-preview/compat"]
io-compat = ["compat", "futures-util-preview/io-compat"]
threadpool = ["futures-executor-preview/threadpool"]

# Unstable features
# These features are outside of the normal semver guarantees and require the
Expand Down
4 changes: 3 additions & 1 deletion futures/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,11 @@ pub mod executor {
BlockingStream,
Enter, EnterError,
LocalSpawner, LocalPool,
ThreadPool, ThreadPoolBuilder,
block_on, block_on_stream, enter,
};

#[cfg(feature = "threadpool")]
pub use futures_executor::{ThreadPool, ThreadPoolBuilder};
}

pub mod future {
Expand Down