Skip to content

Commit

Permalink
Support shared futures on no_std
Browse files Browse the repository at this point in the history
  • Loading branch information
adavis628 committed Jul 2, 2024
1 parent c507ff8 commit adcae3c
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 12 deletions.
1 change: 1 addition & 0 deletions futures-util/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ futures_01 = { version = "0.1.25", optional = true, package = "futures" }
tokio-io = { version = "0.1.9", optional = true }
pin-utils = "0.1.0"
pin-project-lite = "0.2.6"
spin = "0.9.8"

[dev-dependencies]
futures = { path = "../futures", features = ["async-await", "thread-pool"] }
Expand Down
6 changes: 3 additions & 3 deletions futures-util/src/future/future/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,9 @@ mod remote_handle;
#[cfg(feature = "std")]
pub use self::remote_handle::{Remote, RemoteHandle};

#[cfg(feature = "std")]
#[cfg(feature = "alloc")]
mod shared;
#[cfg(feature = "std")]
#[cfg(feature = "alloc")]
pub use self::shared::{Shared, WeakShared};

impl<T: ?Sized> FutureExt for T where T: Future {}
Expand Down Expand Up @@ -474,7 +474,7 @@ pub trait FutureExt: Future {
/// join_handle.join().unwrap();
/// # });
/// ```
#[cfg(feature = "std")]
#[cfg(feature = "alloc")]
fn shared(self) -> Shared<Self>
where
Self: Sized,
Expand Down
21 changes: 13 additions & 8 deletions futures-util/src/future/future/shared.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
use crate::task::{waker_ref, ArcWake};
use alloc::sync::{Arc, Weak};
use core::cell::UnsafeCell;
use core::fmt;
use core::hash::Hasher;
use core::pin::Pin;
use core::ptr;
use core::sync::atomic::AtomicUsize;
use core::sync::atomic::Ordering::{Acquire, SeqCst};
use futures_core::future::{FusedFuture, Future};
use futures_core::task::{Context, Poll, Waker};
use slab::Slab;
use std::cell::UnsafeCell;
use std::fmt;
use std::hash::Hasher;
use std::pin::Pin;
use std::ptr;
use std::sync::atomic::AtomicUsize;
use std::sync::atomic::Ordering::{Acquire, SeqCst};
use std::sync::{Arc, Mutex, Weak};

#[cfg(feature = "std")]
type Mutex<T> = std::sync::Mutex<T>;
#[cfg(not(feature = "std"))]
type Mutex<T> = spin::Mutex<T>;

/// Future for the [`shared`](super::FutureExt::shared) method.
#[must_use = "futures do nothing unless you `.await` or poll them"]
Expand Down
2 changes: 1 addition & 1 deletion futures-util/src/future/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ pub use self::future::CatchUnwind;
#[cfg(feature = "std")]
pub use self::future::{Remote, RemoteHandle};

#[cfg(feature = "std")]
#[cfg(feature = "alloc")]
pub use self::future::{Shared, WeakShared};

mod try_future;
Expand Down

0 comments on commit adcae3c

Please sign in to comment.