diff options
author | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2022-05-10 07:01:18 +0000 |
---|---|---|
committer | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2022-05-10 07:01:18 +0000 |
commit | b7cac5c579c294fc549b31b57c5cc14642c72531 (patch) | |
tree | 695013359c187d2948f2e46f268e261698497aa3 | |
parent | 3619c28f407eeb71d739672b653d677dd4bebf17 (diff) | |
parent | 5218f7c51e621a7545d60a71d0ba6e7ed146da0d (diff) | |
download | futures-task-android13-mainline-permission-release.tar.gz |
Snap for 8564071 from 5218f7c51e621a7545d60a71d0ba6e7ed146da0d to mainline-permission-releaseaml_per_331913010aml_per_331812030aml_per_331710050aml_per_331611010aml_per_331512020aml_per_331411000aml_per_331313010aml_per_331115020aml_per_331019040aml_per_330912010aml_per_330811030android13-mainline-permission-release
Change-Id: I69d54d6d32ab002b04a75140257b5a7fd2eb23ce
-rw-r--r-- | .cargo_vcs_info.json | 7 | ||||
-rw-r--r-- | Android.bp | 26 | ||||
-rw-r--r-- | Cargo.toml | 19 | ||||
-rw-r--r-- | Cargo.toml.orig | 10 | ||||
-rw-r--r-- | METADATA | 8 | ||||
-rw-r--r-- | README.md | 23 | ||||
-rw-r--r-- | TEST_MAPPING | 150 | ||||
-rw-r--r-- | build.rs | 41 | ||||
-rw-r--r-- | cargo2android.json | 5 | ||||
-rw-r--r-- | no_atomic_cas.rs | 13 | ||||
-rw-r--r-- | src/future_obj.rs | 68 | ||||
-rw-r--r-- | src/lib.rs | 60 | ||||
-rw-r--r-- | src/spawn.rs | 34 | ||||
-rw-r--r-- | src/waker.rs | 18 | ||||
-rw-r--r-- | src/waker_ref.rs | 25 |
15 files changed, 223 insertions, 284 deletions
diff --git a/.cargo_vcs_info.json b/.cargo_vcs_info.json index f3ad3ab..1f750b1 100644 --- a/.cargo_vcs_info.json +++ b/.cargo_vcs_info.json @@ -1,5 +1,6 @@ { "git": { - "sha1": "c91f8691672c7401b1923ab00bf138975c99391a" - } -} + "sha1": "fc1e3250219170e31cddb8857a276cba7dd08d44" + }, + "path_in_vcs": "futures-task" +}
\ No newline at end of file @@ -37,12 +37,18 @@ license { ], } -rust_defaults { - name: "futures-task_defaults", +rust_test { + name: "futures-task_test_src_lib", + host_supported: true, crate_name: "futures_task", + cargo_env_compat: true, + cargo_pkg_version: "0.3.21", srcs: ["src/lib.rs"], test_suites: ["general-tests"], auto_gen_config: true, + test_options: { + unit_test: true, + }, edition: "2018", features: [ "alloc", @@ -51,23 +57,12 @@ rust_defaults { ], } -rust_test_host { - name: "futures-task_host_test_src_lib", - defaults: ["futures-task_defaults"], - test_options: { - unit_test: true, - }, -} - -rust_test { - name: "futures-task_device_test_src_lib", - defaults: ["futures-task_defaults"], -} - rust_library { name: "libfutures_task", host_supported: true, crate_name: "futures_task", + cargo_env_compat: true, + cargo_pkg_version: "0.3.21", srcs: ["src/lib.rs"], edition: "2018", features: [ @@ -77,6 +72,7 @@ rust_library { ], apex_available: [ "//apex_available:platform", + "com.android.bluetooth", "com.android.resolv", "com.android.virt", ], @@ -3,23 +3,24 @@ # When uploading crates to the registry Cargo will automatically # "normalize" Cargo.toml files for maximal compatibility # with all versions of Cargo and also rewrite `path` dependencies -# to registry (e.g., crates.io) dependencies +# to registry (e.g., crates.io) dependencies. # -# If you believe there's an error in this file please file an -# issue against the rust-lang/cargo repository. If you're -# editing this file be aware that the upstream Cargo.toml -# will likely look very different (and much more reasonable) +# If you are reading this file be aware that the original Cargo.toml +# will likely look very different (and much more reasonable). +# See Cargo.toml.orig for the original contents. [package] edition = "2018" +rust-version = "1.45" name = "futures-task" -version = "0.3.13" -authors = ["Alex Crichton <alex@alexcrichton.com>"] -description = "Tools for working with tasks.\n" +version = "0.3.21" +description = """ +Tools for working with tasks. +""" homepage = "https://rust-lang.github.io/futures-rs" -documentation = "https://docs.rs/futures-task/0.3" license = "MIT OR Apache-2.0" repository = "https://github.com/rust-lang/futures-rs" + [package.metadata.docs.rs] all-features = true diff --git a/Cargo.toml.orig b/Cargo.toml.orig index 764a692..77fec6f 100644 --- a/Cargo.toml.orig +++ b/Cargo.toml.orig @@ -1,12 +1,11 @@ [package] name = "futures-task" +version = "0.3.21" edition = "2018" -version = "0.3.13" -authors = ["Alex Crichton <alex@alexcrichton.com>"] +rust-version = "1.45" license = "MIT OR Apache-2.0" repository = "https://github.com/rust-lang/futures-rs" homepage = "https://rust-lang.github.io/futures-rs" -documentation = "https://docs.rs/futures-task/0.3" description = """ Tools for working with tasks. """ @@ -16,9 +15,8 @@ default = ["std"] std = ["alloc"] alloc = [] -# Unstable features -# These features are outside of the normal semver guarantees and require the -# `unstable` feature as an explicit opt-in to unstable API. +# These features are no longer used. +# TODO: remove in the next major version. unstable = [] cfg-target-has-atomic = [] @@ -7,13 +7,13 @@ third_party { } url { type: ARCHIVE - value: "https://static.crates.io/crates/futures-task/futures-task-0.3.13.crate" + value: "https://static.crates.io/crates/futures-task/futures-task-0.3.21.crate" } - version: "0.3.13" + version: "0.3.21" license_type: NOTICE last_upgrade_date { - year: 2021 - month: 4 + year: 2022 + month: 3 day: 1 } } diff --git a/README.md b/README.md new file mode 100644 index 0000000..8ceeba9 --- /dev/null +++ b/README.md @@ -0,0 +1,23 @@ +# futures-task + +Tools for working with tasks. + +## Usage + +Add this to your `Cargo.toml`: + +```toml +[dependencies] +futures-task = "0.3" +``` + +The current `futures-task` requires Rust 1.45 or later. + +## License + +Licensed under either of [Apache License, Version 2.0](LICENSE-APACHE) or +[MIT license](LICENSE-MIT) at your option. + +Unless you explicitly state otherwise, any contribution intentionally submitted +for inclusion in the work by you, as defined in the Apache-2.0 license, shall +be dual licensed as above, without any additional terms or conditions. diff --git a/TEST_MAPPING b/TEST_MAPPING index 723e5ac..64f7c12 100644 --- a/TEST_MAPPING +++ b/TEST_MAPPING @@ -1,161 +1,51 @@ // Generated by update_crate_tests.py for tests that depend on this crate. { - "presubmit": [ - { - "name": "ZipFuseTest" - }, - { - "name": "anyhow_device_test_src_lib" - }, - { - "name": "anyhow_device_test_tests_test_autotrait" - }, - { - "name": "anyhow_device_test_tests_test_boxed" - }, - { - "name": "anyhow_device_test_tests_test_chain" - }, - { - "name": "anyhow_device_test_tests_test_context" - }, + "imports": [ { - "name": "anyhow_device_test_tests_test_convert" + "path": "external/rust/crates/anyhow" }, { - "name": "anyhow_device_test_tests_test_downcast" + "path": "external/rust/crates/futures-util" }, { - "name": "anyhow_device_test_tests_test_ffi" + "path": "external/rust/crates/tokio" }, { - "name": "anyhow_device_test_tests_test_fmt" - }, - { - "name": "anyhow_device_test_tests_test_macros" - }, - { - "name": "anyhow_device_test_tests_test_repr" - }, + "path": "external/rust/crates/tokio-test" + } + ], + "presubmit": [ { - "name": "anyhow_device_test_tests_test_source" + "name": "ZipFuseTest" }, { "name": "authfs_device_test_src_lib" }, { - "name": "futures-task_device_test_src_lib" - }, - { - "name": "futures-util_device_test_src_lib" - }, - { - "name": "tokio-test_device_test_src_lib" - }, - { - "name": "tokio-test_device_test_tests_block_on" - }, - { - "name": "tokio-test_device_test_tests_io" - }, - { - "name": "tokio-test_device_test_tests_macros" - }, - { - "name": "tokio_device_test_tests_buffered" - }, - { - "name": "tokio_device_test_tests_io_async_read" - }, - { - "name": "tokio_device_test_tests_io_copy_bidirectional" - }, - { - "name": "tokio_device_test_tests_io_lines" - }, - { - "name": "tokio_device_test_tests_io_mem_stream" - }, - { - "name": "tokio_device_test_tests_io_read" - }, - { - "name": "tokio_device_test_tests_io_read_buf" - }, - { - "name": "tokio_device_test_tests_io_read_to_end" - }, - { - "name": "tokio_device_test_tests_io_take" - }, - { - "name": "tokio_device_test_tests_io_write" - }, - { - "name": "tokio_device_test_tests_io_write_all" + "name": "doh_unit_test" }, { - "name": "tokio_device_test_tests_io_write_buf" + "name": "futures-task_test_src_lib" }, { - "name": "tokio_device_test_tests_io_write_int" - }, - { - "name": "tokio_device_test_tests_macros_join" - }, - { - "name": "tokio_device_test_tests_no_rt" - }, - { - "name": "tokio_device_test_tests_rt_basic" - }, - { - "name": "tokio_device_test_tests_rt_threaded" - }, - { - "name": "tokio_device_test_tests_sync_barrier" - }, - { - "name": "tokio_device_test_tests_sync_broadcast" - }, - { - "name": "tokio_device_test_tests_sync_errors" - }, - { - "name": "tokio_device_test_tests_sync_mpsc" - }, - { - "name": "tokio_device_test_tests_sync_mutex_owned" - }, - { - "name": "tokio_device_test_tests_sync_rwlock" - }, - { - "name": "tokio_device_test_tests_sync_watch" - }, - { - "name": "tokio_device_test_tests_task_local" - }, - { - "name": "tokio_device_test_tests_task_local_set" - }, - { - "name": "tokio_device_test_tests_tcp_accept" - }, + "name": "virtualizationservice_device_test" + } + ], + "presubmit-rust": [ { - "name": "tokio_device_test_tests_tcp_echo" + "name": "ZipFuseTest" }, { - "name": "tokio_device_test_tests_tcp_into_std" + "name": "authfs_device_test_src_lib" }, { - "name": "tokio_device_test_tests_tcp_shutdown" + "name": "doh_unit_test" }, { - "name": "tokio_device_test_tests_time_rt" + "name": "futures-task_test_src_lib" }, { - "name": "tokio_device_test_tests_uds_split" + "name": "virtualizationservice_device_test" } ] } diff --git a/build.rs b/build.rs new file mode 100644 index 0000000..05e0496 --- /dev/null +++ b/build.rs @@ -0,0 +1,41 @@ +// The rustc-cfg listed below are considered public API, but it is *unstable* +// and outside of the normal semver guarantees: +// +// - `futures_no_atomic_cas` +// Assume the target does *not* support atomic CAS operations. +// This is usually detected automatically by the build script, but you may +// need to enable it manually when building for custom targets or using +// non-cargo build systems that don't run the build script. +// +// With the exceptions mentioned above, the rustc-cfg emitted by the build +// script are *not* public API. + +#![warn(rust_2018_idioms, single_use_lifetimes)] + +use std::env; + +include!("no_atomic_cas.rs"); + +fn main() { + let target = match env::var("TARGET") { + Ok(target) => target, + Err(e) => { + println!( + "cargo:warning={}: unable to get TARGET environment variable: {}", + env!("CARGO_PKG_NAME"), + e + ); + return; + } + }; + + // Note that this is `no_*`, not `has_*`. This allows treating + // `cfg(target_has_atomic = "ptr")` as true when the build script doesn't + // run. This is needed for compatibility with non-cargo build systems that + // don't run the build script. + if NO_ATOMIC_CAS.contains(&&*target) { + println!("cargo:rustc-cfg=futures_no_atomic_cas"); + } + + println!("cargo:rerun-if-changed=no_atomic_cas.rs"); +} diff --git a/cargo2android.json b/cargo2android.json index 44e747c..5b266a6 100644 --- a/cargo2android.json +++ b/cargo2android.json @@ -1,12 +1,13 @@ { "apex-available": [ "//apex_available:platform", + "com.android.bluetooth", "com.android.resolv", "com.android.virt" ], - "min_sdk_version": "29", "dependencies": true, "device": true, + "min-sdk-version": "29", "run": true, "tests": true -}
\ No newline at end of file +} diff --git a/no_atomic_cas.rs b/no_atomic_cas.rs new file mode 100644 index 0000000..9b05d4b --- /dev/null +++ b/no_atomic_cas.rs @@ -0,0 +1,13 @@ +// This file is @generated by no_atomic_cas.sh. +// It is not intended for manual editing. + +const NO_ATOMIC_CAS: &[&str] = &[ + "avr-unknown-gnu-atmega328", + "bpfeb-unknown-none", + "bpfel-unknown-none", + "msp430-none-elf", + "riscv32i-unknown-none-elf", + "riscv32imc-unknown-none-elf", + "thumbv4t-none-eabi", + "thumbv6m-none-eabi", +]; diff --git a/src/future_obj.rs b/src/future_obj.rs index 373be24..f67494a 100644 --- a/src/future_obj.rs +++ b/src/future_obj.rs @@ -1,8 +1,8 @@ use core::{ - mem, fmt, future::Future, marker::PhantomData, + mem, pin::Pin, task::{Context, Poll}, }; @@ -26,16 +26,16 @@ impl<T> Unpin for LocalFutureObj<'_, T> {} #[allow(single_use_lifetimes)] #[allow(clippy::transmute_ptr_to_ptr)] -unsafe fn remove_future_lifetime<'a, T>(ptr: *mut (dyn Future<Output = T> + 'a)) - -> *mut (dyn Future<Output = T> + 'static) -{ +unsafe fn remove_future_lifetime<'a, T>( + ptr: *mut (dyn Future<Output = T> + 'a), +) -> *mut (dyn Future<Output = T> + 'static) { mem::transmute(ptr) } #[allow(single_use_lifetimes)] -unsafe fn remove_drop_lifetime<'a, T>(ptr: unsafe fn (*mut (dyn Future<Output = T> + 'a))) - -> unsafe fn(*mut (dyn Future<Output = T> + 'static)) -{ +unsafe fn remove_drop_lifetime<'a, T>( + ptr: unsafe fn(*mut (dyn Future<Output = T> + 'a)), +) -> unsafe fn(*mut (dyn Future<Output = T> + 'static)) { mem::transmute(ptr) } @@ -65,8 +65,7 @@ impl<'a, T> LocalFutureObj<'a, T> { impl<T> fmt::Debug for LocalFutureObj<'_, T> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - f.debug_struct("LocalFutureObj") - .finish() + f.debug_struct("LocalFutureObj").finish() } } @@ -82,17 +81,13 @@ impl<T> Future for LocalFutureObj<'_, T> { #[inline] fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<T> { - unsafe { - Pin::new_unchecked(&mut *self.future).poll(cx) - } + unsafe { Pin::new_unchecked(&mut *self.future).poll(cx) } } } impl<T> Drop for LocalFutureObj<'_, T> { fn drop(&mut self) { - unsafe { - (self.drop_fn)(self.future) - } + unsafe { (self.drop_fn)(self.future) } } } @@ -120,8 +115,7 @@ impl<'a, T> FutureObj<'a, T> { impl<T> fmt::Debug for FutureObj<'_, T> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - f.debug_struct("FutureObj") - .finish() + f.debug_struct("FutureObj").finish() } } @@ -130,7 +124,7 @@ impl<T> Future for FutureObj<'_, T> { #[inline] fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<T> { - Pin::new( &mut self.0 ).poll(cx) + Pin::new(&mut self.0).poll(cx) } } @@ -180,7 +174,7 @@ pub unsafe trait UnsafeFutureObj<'a, T>: 'a { unsafe impl<'a, T, F> UnsafeFutureObj<'a, T> for &'a mut F where - F: Future<Output = T> + Unpin + 'a + F: Future<Output = T> + Unpin + 'a, { fn into_raw(self) -> *mut (dyn Future<Output = T> + 'a) { self as *mut dyn Future<Output = T> @@ -189,8 +183,7 @@ where unsafe fn drop(_ptr: *mut (dyn Future<Output = T> + 'a)) {} } -unsafe impl<'a, T> UnsafeFutureObj<'a, T> for &'a mut (dyn Future<Output = T> + Unpin + 'a) -{ +unsafe impl<'a, T> UnsafeFutureObj<'a, T> for &'a mut (dyn Future<Output = T> + Unpin + 'a) { fn into_raw(self) -> *mut (dyn Future<Output = T> + 'a) { self as *mut dyn Future<Output = T> } @@ -200,7 +193,7 @@ unsafe impl<'a, T> UnsafeFutureObj<'a, T> for &'a mut (dyn Future<Output = T> + unsafe impl<'a, T, F> UnsafeFutureObj<'a, T> for Pin<&'a mut F> where - F: Future<Output = T> + 'a + F: Future<Output = T> + 'a, { fn into_raw(self) -> *mut (dyn Future<Output = T> + 'a) { unsafe { self.get_unchecked_mut() as *mut dyn Future<Output = T> } @@ -209,8 +202,7 @@ where unsafe fn drop(_ptr: *mut (dyn Future<Output = T> + 'a)) {} } -unsafe impl<'a, T> UnsafeFutureObj<'a, T> for Pin<&'a mut (dyn Future<Output = T> + 'a)> -{ +unsafe impl<'a, T> UnsafeFutureObj<'a, T> for Pin<&'a mut (dyn Future<Output = T> + 'a)> { fn into_raw(self) -> *mut (dyn Future<Output = T> + 'a) { unsafe { self.get_unchecked_mut() as *mut dyn Future<Output = T> } } @@ -224,14 +216,15 @@ mod if_alloc { use alloc::boxed::Box; unsafe impl<'a, T, F> UnsafeFutureObj<'a, T> for Box<F> - where F: Future<Output = T> + 'a + where + F: Future<Output = T> + 'a, { fn into_raw(self) -> *mut (dyn Future<Output = T> + 'a) { Box::into_raw(self) } unsafe fn drop(ptr: *mut (dyn Future<Output = T> + 'a)) { - drop(Box::from_raw(ptr as *mut F)) + drop(Box::from_raw(ptr.cast::<F>())) } } @@ -257,12 +250,11 @@ mod if_alloc { unsafe impl<'a, T, F> UnsafeFutureObj<'a, T> for Pin<Box<F>> where - F: Future<Output = T> + 'a + F: Future<Output = T> + 'a, { - fn into_raw(mut self) -> *mut (dyn Future<Output = T> + 'a) { - let ptr = unsafe { self.as_mut().get_unchecked_mut() as *mut _ }; - mem::forget(self); - ptr + fn into_raw(self) -> *mut (dyn Future<Output = T> + 'a) { + let mut this = mem::ManuallyDrop::new(self); + unsafe { this.as_mut().get_unchecked_mut() as *mut _ } } unsafe fn drop(ptr: *mut (dyn Future<Output = T> + 'a)) { @@ -271,10 +263,9 @@ mod if_alloc { } unsafe impl<'a, T: 'a> UnsafeFutureObj<'a, T> for Pin<Box<dyn Future<Output = T> + 'a>> { - fn into_raw(mut self) -> *mut (dyn Future<Output = T> + 'a) { - let ptr = unsafe { self.as_mut().get_unchecked_mut() as *mut _ }; - mem::forget(self); - ptr + fn into_raw(self) -> *mut (dyn Future<Output = T> + 'a) { + let mut this = mem::ManuallyDrop::new(self); + unsafe { this.as_mut().get_unchecked_mut() as *mut _ } } unsafe fn drop(ptr: *mut (dyn Future<Output = T> + 'a)) { @@ -283,10 +274,9 @@ mod if_alloc { } unsafe impl<'a, T: 'a> UnsafeFutureObj<'a, T> for Pin<Box<dyn Future<Output = T> + Send + 'a>> { - fn into_raw(mut self) -> *mut (dyn Future<Output = T> + 'a) { - let ptr = unsafe { self.as_mut().get_unchecked_mut() as *mut _ }; - mem::forget(self); - ptr + fn into_raw(self) -> *mut (dyn Future<Output = T> + 'a) { + let mut this = mem::ManuallyDrop::new(self); + unsafe { this.as_mut().get_unchecked_mut() as *mut _ } } unsafe fn drop(ptr: *mut (dyn Future<Output = T> + 'a)) { @@ -1,47 +1,43 @@ //! Tools for working with tasks. -#![cfg_attr(feature = "cfg-target-has-atomic", feature(cfg_target_has_atomic))] - #![cfg_attr(not(feature = "std"), no_std)] - -#![warn(missing_docs, missing_debug_implementations, rust_2018_idioms, unreachable_pub)] +#![warn(missing_debug_implementations, missing_docs, rust_2018_idioms, unreachable_pub)] // It cannot be included in the published code because this lints have false positives in the minimum required version. #![cfg_attr(test, warn(single_use_lifetimes))] -#![warn(clippy::all)] -#![doc(test(attr(deny(warnings), allow(dead_code, unused_assignments, unused_variables))))] - -#[cfg(all(feature = "cfg-target-has-atomic", not(feature = "unstable")))] -compile_error!("The `cfg-target-has-atomic` feature requires the `unstable` feature as an explicit opt-in to unstable features"); +#![doc(test( + no_crate_inject, + attr( + deny(warnings, rust_2018_idioms, single_use_lifetimes), + allow(dead_code, unused_assignments, unused_variables) + ) +))] #[cfg(feature = "alloc")] extern crate alloc; -macro_rules! cfg_target_has_atomic { - ($($item:item)*) => {$( - #[cfg_attr(feature = "cfg-target-has-atomic", cfg(target_has_atomic = "ptr"))] - $item - )*}; -} - mod spawn; -pub use crate::spawn::{Spawn, SpawnError, LocalSpawn}; +pub use crate::spawn::{LocalSpawn, Spawn, SpawnError}; -cfg_target_has_atomic! { - #[cfg(feature = "alloc")] - mod arc_wake; - #[cfg(feature = "alloc")] - pub use crate::arc_wake::ArcWake; +#[cfg(not(futures_no_atomic_cas))] +#[cfg(feature = "alloc")] +mod arc_wake; +#[cfg(not(futures_no_atomic_cas))] +#[cfg(feature = "alloc")] +pub use crate::arc_wake::ArcWake; - #[cfg(feature = "alloc")] - mod waker; - #[cfg(feature = "alloc")] - pub use crate::waker::waker; +#[cfg(not(futures_no_atomic_cas))] +#[cfg(feature = "alloc")] +mod waker; +#[cfg(not(futures_no_atomic_cas))] +#[cfg(feature = "alloc")] +pub use crate::waker::waker; - #[cfg(feature = "alloc")] - mod waker_ref; - #[cfg(feature = "alloc")] - pub use crate::waker_ref::{waker_ref, WakerRef}; -} +#[cfg(not(futures_no_atomic_cas))] +#[cfg(feature = "alloc")] +mod waker_ref; +#[cfg(not(futures_no_atomic_cas))] +#[cfg(feature = "alloc")] +pub use crate::waker_ref::{waker_ref, WakerRef}; mod future_obj; pub use crate::future_obj::{FutureObj, LocalFutureObj, UnsafeFutureObj}; @@ -51,4 +47,4 @@ pub use crate::noop_waker::noop_waker; pub use crate::noop_waker::noop_waker_ref; #[doc(no_inline)] -pub use core::task::{Context, Poll, Waker, RawWaker, RawWakerVTable}; +pub use core::task::{Context, Poll, RawWaker, RawWakerVTable, Waker}; diff --git a/src/spawn.rs b/src/spawn.rs index a515dd4..f4e6339 100644 --- a/src/spawn.rs +++ b/src/spawn.rs @@ -126,7 +126,7 @@ impl<Sp: ?Sized + LocalSpawn> LocalSpawn for &mut Sp { #[cfg(feature = "alloc")] mod if_alloc { use super::*; - use alloc::{ boxed::Box, rc::Rc }; + use alloc::{boxed::Box, rc::Rc}; impl<Sp: ?Sized + Spawn> Spawn for Box<Sp> { fn spawn_obj(&self, future: FutureObj<'static, ()>) -> Result<(), SpawnError> { @@ -168,27 +168,25 @@ mod if_alloc { } } - cfg_target_has_atomic! { - use alloc::{ sync::Arc }; - - impl<Sp: ?Sized + Spawn> Spawn for Arc<Sp> { - fn spawn_obj(&self, future: FutureObj<'static, ()>) -> Result<(), SpawnError> { - (**self).spawn_obj(future) - } + #[cfg(not(futures_no_atomic_cas))] + impl<Sp: ?Sized + Spawn> Spawn for alloc::sync::Arc<Sp> { + fn spawn_obj(&self, future: FutureObj<'static, ()>) -> Result<(), SpawnError> { + (**self).spawn_obj(future) + } - fn status(&self) -> Result<(), SpawnError> { - (**self).status() - } + fn status(&self) -> Result<(), SpawnError> { + (**self).status() } + } - impl<Sp: ?Sized + LocalSpawn> LocalSpawn for Arc<Sp> { - fn spawn_local_obj(&self, future: LocalFutureObj<'static, ()>) -> Result<(), SpawnError> { - (**self).spawn_local_obj(future) - } + #[cfg(not(futures_no_atomic_cas))] + impl<Sp: ?Sized + LocalSpawn> LocalSpawn for alloc::sync::Arc<Sp> { + fn spawn_local_obj(&self, future: LocalFutureObj<'static, ()>) -> Result<(), SpawnError> { + (**self).spawn_local_obj(future) + } - fn status_local(&self) -> Result<(), SpawnError> { - (**self).status_local() - } + fn status_local(&self) -> Result<(), SpawnError> { + (**self).status_local() } } } diff --git a/src/waker.rs b/src/waker.rs index 265a445..7911256 100644 --- a/src/waker.rs +++ b/src/waker.rs @@ -1,7 +1,7 @@ use super::arc_wake::ArcWake; -use core::mem; -use core::task::{Waker, RawWaker, RawWakerVTable}; use alloc::sync::Arc; +use core::mem; +use core::task::{RawWaker, RawWakerVTable, Waker}; pub(super) fn waker_vtable<W: ArcWake>() -> &'static RawWakerVTable { &RawWakerVTable::new( @@ -20,11 +20,9 @@ pub fn waker<W>(wake: Arc<W>) -> Waker where W: ArcWake + 'static, { - let ptr = Arc::into_raw(wake) as *const (); + let ptr = Arc::into_raw(wake).cast::<()>(); - unsafe { - Waker::from_raw(RawWaker::new(ptr, waker_vtable::<W>())) - } + unsafe { Waker::from_raw(RawWaker::new(ptr, waker_vtable::<W>())) } } // FIXME: panics on Arc::clone / refcount changes could wreak havoc on the @@ -33,7 +31,7 @@ where #[allow(clippy::redundant_clone)] // The clone here isn't actually redundant. unsafe fn increase_refcount<T: ArcWake>(data: *const ()) { // Retain Arc, but don't touch refcount by wrapping in ManuallyDrop - let arc = mem::ManuallyDrop::new(Arc::<T>::from_raw(data as *const T)); + let arc = mem::ManuallyDrop::new(Arc::<T>::from_raw(data.cast::<T>())); // Now increase refcount, but don't drop new refcount either let _arc_clone: mem::ManuallyDrop<_> = arc.clone(); } @@ -45,17 +43,17 @@ unsafe fn clone_arc_raw<T: ArcWake>(data: *const ()) -> RawWaker { } unsafe fn wake_arc_raw<T: ArcWake>(data: *const ()) { - let arc: Arc<T> = Arc::from_raw(data as *const T); + let arc: Arc<T> = Arc::from_raw(data.cast::<T>()); ArcWake::wake(arc); } // used by `waker_ref` unsafe fn wake_by_ref_arc_raw<T: ArcWake>(data: *const ()) { // Retain Arc, but don't touch refcount by wrapping in ManuallyDrop - let arc = mem::ManuallyDrop::new(Arc::<T>::from_raw(data as *const T)); + let arc = mem::ManuallyDrop::new(Arc::<T>::from_raw(data.cast::<T>())); ArcWake::wake_by_ref(&arc); } unsafe fn drop_arc_raw<T: ArcWake>(data: *const ()) { - drop(Arc::<T>::from_raw(data as *const T)) + drop(Arc::<T>::from_raw(data.cast::<T>())) } diff --git a/src/waker_ref.rs b/src/waker_ref.rs index 76d849a..7fb552f 100644 --- a/src/waker_ref.rs +++ b/src/waker_ref.rs @@ -1,10 +1,10 @@ -use super::arc_wake::{ArcWake}; +use super::arc_wake::ArcWake; use super::waker::waker_vtable; use alloc::sync::Arc; -use core::mem::ManuallyDrop; use core::marker::PhantomData; +use core::mem::ManuallyDrop; use core::ops::Deref; -use core::task::{Waker, RawWaker}; +use core::task::{RawWaker, Waker}; /// A [`Waker`] that is only valid for a given lifetime. /// @@ -22,10 +22,7 @@ impl<'a> WakerRef<'a> { // copy the underlying (raw) waker without calling a clone, // as we won't call Waker::drop either. let waker = ManuallyDrop::new(unsafe { core::ptr::read(waker) }); - Self { - waker, - _marker: PhantomData, - } + Self { waker, _marker: PhantomData } } /// Create a new [`WakerRef`] from a [`Waker`] that must not be dropped. @@ -35,10 +32,7 @@ impl<'a> WakerRef<'a> { /// by the caller), and the [`Waker`] doesn't need to or must not be /// destroyed. pub fn new_unowned(waker: ManuallyDrop<Waker>) -> Self { - Self { - waker, - _marker: PhantomData, - } + Self { waker, _marker: PhantomData } } } @@ -57,14 +51,13 @@ impl Deref for WakerRef<'_> { #[inline] pub fn waker_ref<W>(wake: &Arc<W>) -> WakerRef<'_> where - W: ArcWake + W: ArcWake, { // simply copy the pointer instead of using Arc::into_raw, // as we don't actually keep a refcount by using ManuallyDrop.< - let ptr = (&**wake as *const W) as *const (); + let ptr = Arc::as_ptr(wake).cast::<()>(); - let waker = ManuallyDrop::new(unsafe { - Waker::from_raw(RawWaker::new(ptr, waker_vtable::<W>())) - }); + let waker = + ManuallyDrop::new(unsafe { Waker::from_raw(RawWaker::new(ptr, waker_vtable::<W>())) }); WakerRef::new_unowned(waker) } |