diff --git a/examples/cpu_monitor.rs b/examples/cpu_monitor.rs index 7c0b2e1da..85b5f848d 100644 --- a/examples/cpu_monitor.rs +++ b/examples/cpu_monitor.rs @@ -77,16 +77,9 @@ fn task_stall_root(args: &Args) { rayon::join(|| task(args), || wait_for_user()); } -#[cfg(rayon_unstable)] fn task_stall_scope(args: &Args) { rayon::scope(|scope| { scope.spawn(move |_| task(args)); scope.spawn(move |_| wait_for_user()); }); } - -#[cfg(not(rayon_unstable))] -fn task_stall_scope(_args: &Args) { - println!("try `RUSTFLAGS='--cfg rayon_unstable' cargo run`"); - process::exit(1); -} diff --git a/rayon-core/src/lib.rs b/rayon-core/src/lib.rs index 9c750daac..e14890624 100644 --- a/rayon-core/src/lib.rs +++ b/rayon-core/src/lib.rs @@ -55,7 +55,6 @@ mod registry; mod future; mod scope; mod sleep; -#[cfg(rayon_unstable)] mod spawn; mod test; mod thread_pool; @@ -67,7 +66,6 @@ pub use thread_pool::current_thread_index; pub use thread_pool::current_thread_has_pending_tasks; pub use join::join; pub use scope::{scope, Scope}; -#[cfg(rayon_unstable)] pub use spawn::spawn; #[cfg(rayon_unstable)] pub use spawn::spawn_future; diff --git a/rayon-core/src/spawn/mod.rs b/rayon-core/src/spawn/mod.rs index 5c5ee1802..caf7c20a4 100644 --- a/rayon-core/src/spawn/mod.rs +++ b/rayon-core/src/spawn/mod.rs @@ -1,3 +1,4 @@ +#[cfg(rayon_unstable)] use future::{self, Future, RayonFuture}; #[allow(unused_imports)] use latch::{Latch, SpinLatch}; @@ -108,6 +109,7 @@ pub unsafe fn spawn_in(func: F, registry: &Arc) /// /// If this future should panic, that panic will be propagated when /// `poll()` is invoked on the return value. +#[cfg(rayon_unstable)] pub fn spawn_future(future: F) -> RayonFuture where F: Future + Send + 'static { @@ -118,6 +120,7 @@ pub fn spawn_future(future: F) -> RayonFuture /// Internal helper function. /// /// Unsafe because caller must guarantee that `registry` has not yet terminated. +#[cfg(rayon_unstable)] pub unsafe fn spawn_future_in(future: F, registry: Arc) -> RayonFuture where F: Future + Send + 'static { @@ -126,10 +129,12 @@ pub unsafe fn spawn_future_in(future: F, registry: Arc) -> RayonFut future::new_rayon_future(future, scope) } +#[cfg(rayon_unstable)] struct StaticFutureScope { registry: Arc } +#[cfg(rayon_unstable)] impl StaticFutureScope { /// Caller asserts that the registry has not yet terminated. unsafe fn new(registry: Arc) -> Self { @@ -149,6 +154,7 @@ impl StaticFutureScope { /// (b) the lifetime `'static` will not end until a completion /// method is called. This is true because `'static` doesn't /// end until the end of the program. +#[cfg(rayon_unstable)] unsafe impl future::FutureScope<'static> for StaticFutureScope { fn registry(&self) -> Arc { self.registry.clone() diff --git a/rayon-core/src/spawn/test.rs b/rayon-core/src/spawn/test.rs index 0e0c5991d..a56b7def1 100644 --- a/rayon-core/src/spawn/test.rs +++ b/rayon-core/src/spawn/test.rs @@ -1,3 +1,4 @@ +#[cfg(rayon_unstable)] use futures::{lazy, Future}; use scope; @@ -6,7 +7,9 @@ use std::sync::{Arc, Mutex}; use std::sync::mpsc::channel; use {Configuration, ThreadPool}; -use super::{spawn, spawn_future}; +use super::spawn; +#[cfg(rayon_unstable)] +use super::spawn_future; #[test] fn spawn_then_join_in_worker() { @@ -50,6 +53,7 @@ fn panic_fwd() { } #[test] +#[cfg(rayon_unstable)] fn async_future_map() { let data = Arc::new(Mutex::new(format!("Hello, "))); @@ -70,6 +74,7 @@ fn async_future_map() { #[test] #[should_panic(expected = "Hello, world!")] +#[cfg(rayon_unstable)] fn async_future_panic_prop() { let future = spawn_future(lazy(move || Ok::<(), ()>(argh()))); let _ = future.rayon_wait(); // should panic, not return a value @@ -82,6 +87,7 @@ fn async_future_panic_prop() { } #[test] +#[cfg(rayon_unstable)] fn async_future_scope_interact() { let future = spawn_future(lazy(move || Ok::(22))); diff --git a/rayon-core/src/thread_pool/mod.rs b/rayon-core/src/thread_pool/mod.rs index bd05ce686..cf74931fb 100644 --- a/rayon-core/src/thread_pool/mod.rs +++ b/rayon-core/src/thread_pool/mod.rs @@ -7,7 +7,6 @@ use log::Event::*; use job::StackJob; use join; use {scope, Scope}; -#[cfg(rayon_unstable)] use spawn; use std::sync::Arc; use std::error::Error; @@ -208,7 +207,6 @@ impl ThreadPool { /// Execute `oper_a` and `oper_b` in the thread-pool and return /// the results. Equivalent to `self.install(|| join(oper_a, /// oper_b))`. - #[cfg(rayon_unstable)] pub fn join(&self, oper_a: A, oper_b: B) -> (RA, RB) where A: FnOnce() -> RA + Send, B: FnOnce() -> RB + Send, @@ -224,7 +222,6 @@ impl ThreadPool { /// See also: [the `scope()` function][scope]. /// /// [scope]: fn.scope.html - #[cfg(rayon_unstable)] pub fn scope<'scope, OP, R>(&self, op: OP) -> R where OP: for<'s> FnOnce(&'s Scope<'scope>) -> R + 'scope + Send, R: Send { @@ -239,7 +236,6 @@ impl ThreadPool { /// See also: [the `spawn()` function defined on scopes][spawn]. /// /// [spawn]: struct.Scope.html#method.spawn - #[cfg(rayon_unstable)] pub fn spawn(&self, op: OP) where OP: FnOnce() + Send + 'static { diff --git a/src/lib.rs b/src/lib.rs index 1fd8dc336..06553d150 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -39,7 +39,6 @@ pub use rayon_core::initialize; pub use rayon_core::ThreadPool; pub use rayon_core::join; pub use rayon_core::{scope, Scope}; -#[cfg(rayon_unstable)] pub use rayon_core::spawn; #[cfg(rayon_unstable)] pub use rayon_core::spawn_future;