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

Allow usage on no_std targets and targets using portable-atomic #7

Merged
merged 5 commits into from
Sep 1, 2022
Merged
Show file tree
Hide file tree
Changes from 4 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
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,9 @@ keywords = ["waker", "notify", "wake", "futures", "async"]
categories = ["asynchronous", "concurrency"]
exclude = ["/.*"]

[dependencies]
# Uses portable-atomic polyfill atomics on targets without them
portable-atomic = { version = "0.3", optional = true }
notgull marked this conversation as resolved.
Show resolved Hide resolved

[dev-dependencies]
futures = "0.3.5"
26 changes: 21 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,26 @@
//! `futures::task::AtomicWaker` extracted into its own crate.
//!
//! # Features
//!
//! This crate adds a feature, `atomic-polyfill`, which uses a polyfill
//! from the [`atomic-polyfill`] crate in order to provide functionality
//! to targets without atomics. See the [`README`] for the [`atomic-polyfill`]
//! crate for more information on how this is implemented by the end-user.
//!
//! [`atomic-polyfill`]: https://crates.io/crates/atomic-polyfill
//! [`README`]: https://github.com/embassy-rs/atomic-polyfill/blob/main/README.md
notgull marked this conversation as resolved.
Show resolved Hide resolved

use std::cell::UnsafeCell;
use std::fmt;
use std::sync::atomic::AtomicUsize;
use std::sync::atomic::Ordering::{AcqRel, Acquire, Release};
use std::task::Waker;
#![no_std]

use core::cell::UnsafeCell;
use core::fmt;
use core::sync::atomic::Ordering::{AcqRel, Acquire, Release};
use core::task::Waker;

#[cfg(not(feature = "portable-atomic"))]
use core::sync::atomic::AtomicUsize;
#[cfg(feature = "portable-atomic")]
use portable_atomic::AtomicUsize;

/// A synchronization primitive for task wakeup.
///
Expand Down