feat: Support for CPU architectures with no atomic instructions

Adds a `portable-atomic` feature to support these architectures.
This commit is contained in:
ivmarkov 2023-10-11 18:43:00 +03:00 committed by GitHub
parent e4131393be
commit f222e1ced0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 18 additions and 2 deletions

View File

@ -51,6 +51,8 @@ jobs:
run: cargo test -- --test-threads=1
env:
CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_RUNNER: valgrind -v --error-exitcode=1 --error-limit=no --leak-check=full --show-leak-kinds=all --track-origins=yes --fair-sched=yes
- name: Run cargo test (with portable-atomic enabled)
run: cargo test --features portable-atomic
- name: Clone async-executor
run: git clone https://github.com/smol-rs/async-executor.git
- name: Add patch section

View File

@ -18,6 +18,10 @@ exclude = ["/.*"]
default = ["std"]
std = []
[dependencies]
# Uses portable-atomic polyfill atomics on targets without them
portable-atomic = { version = "1", optional = true, default-features = false }
[dev-dependencies]
atomic-waker = "1"
easy-parallel = "3"

View File

@ -1,8 +1,13 @@
use core::cell::UnsafeCell;
use core::fmt;
use core::sync::atomic::{AtomicUsize, Ordering};
use core::task::Waker;
#[cfg(not(feature = "portable-atomic"))]
use core::sync::atomic::AtomicUsize;
use core::sync::atomic::Ordering;
#[cfg(feature = "portable-atomic")]
use portable_atomic::AtomicUsize;
use crate::raw::TaskVTable;
use crate::state::*;
use crate::utils::abort_on_panic;

View File

@ -5,9 +5,14 @@ use core::marker::PhantomData;
use core::mem::{self, ManuallyDrop};
use core::pin::Pin;
use core::ptr::NonNull;
use core::sync::atomic::{AtomicUsize, Ordering};
use core::task::{Context, Poll, RawWaker, RawWakerVTable, Waker};
#[cfg(not(feature = "portable-atomic"))]
use core::sync::atomic::AtomicUsize;
use core::sync::atomic::Ordering;
#[cfg(feature = "portable-atomic")]
use portable_atomic::AtomicUsize;
use crate::header::Header;
use crate::runnable::{Schedule, ScheduleInfo};
use crate::state::*;