Allow usage on `no_std` targets and targets using `portable-atomic` (#7)
This commit is contained in:
parent
3d0cfac19e
commit
7c07f0f090
|
@ -29,6 +29,10 @@ jobs:
|
||||||
if: startsWith(matrix.rust, 'nightly')
|
if: startsWith(matrix.rust, 'nightly')
|
||||||
run: cargo check -Z features=dev_dep
|
run: cargo check -Z features=dev_dep
|
||||||
- run: cargo test
|
- run: cargo test
|
||||||
|
- name: Install cargo-hack
|
||||||
|
uses: taiki-e/install-action@cargo-hack
|
||||||
|
- run: rustup target add thumbv7m-none-eabi
|
||||||
|
- run: cargo hack build --target thumbv7m-none-eabi --no-default-features --no-dev-deps
|
||||||
|
|
||||||
msrv:
|
msrv:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
|
@ -19,5 +19,9 @@ keywords = ["waker", "notify", "wake", "futures", "async"]
|
||||||
categories = ["asynchronous", "concurrency"]
|
categories = ["asynchronous", "concurrency"]
|
||||||
exclude = ["/.*"]
|
exclude = ["/.*"]
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
# Uses portable-atomic polyfill atomics on targets without them
|
||||||
|
portable-atomic = { version = "0.3", optional = true, default-features = false }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
futures = "0.3.5"
|
futures = "0.3.5"
|
||||||
|
|
26
src/lib.rs
26
src/lib.rs
|
@ -1,10 +1,26 @@
|
||||||
//! `futures::task::AtomicWaker` extracted into its own crate.
|
//! `futures::task::AtomicWaker` extracted into its own crate.
|
||||||
|
//!
|
||||||
|
//! # Features
|
||||||
|
//!
|
||||||
|
//! This crate adds a feature, `portable-atomic`, which uses a polyfill
|
||||||
|
//! from the [`portable-atomic`] crate in order to provide functionality
|
||||||
|
//! to targets without atomics. See the [`README`] for the [`portable-atomic`]
|
||||||
|
//! crate for more information on how to use it on single-threaded targets.
|
||||||
|
//!
|
||||||
|
//! [`portable-atomic`]: https://crates.io/crates/portable-atomic
|
||||||
|
//! [`README`]: https://github.com/taiki-e/portable-atomic/blob/main/README.md#optional-cfg
|
||||||
|
|
||||||
use std::cell::UnsafeCell;
|
#![no_std]
|
||||||
use std::fmt;
|
|
||||||
use std::sync::atomic::AtomicUsize;
|
use core::cell::UnsafeCell;
|
||||||
use std::sync::atomic::Ordering::{AcqRel, Acquire, Release};
|
use core::fmt;
|
||||||
use std::task::Waker;
|
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.
|
/// A synchronization primitive for task wakeup.
|
||||||
///
|
///
|
||||||
|
|
Loading…
Reference in New Issue