Skip to content

Commit

Permalink
feat: Support for CPU architectures with no atomic instructions
Browse files Browse the repository at this point in the history
Adds a `portable-atomic` feature to support these architectures.
  • Loading branch information
ivmarkov authored Oct 11, 2023
1 parent e413139 commit f222e1c
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
7 changes: 6 additions & 1 deletion src/header.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
7 changes: 6 additions & 1 deletion src/raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;
Expand Down

0 comments on commit f222e1c

Please sign in to comment.