Skip to content

Commit f222e1c

Browse files
authored
feat: Support for CPU architectures with no atomic instructions
Adds a `portable-atomic` feature to support these architectures.
1 parent e413139 commit f222e1c

File tree

4 files changed

+18
-2
lines changed

4 files changed

+18
-2
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ jobs:
5151
run: cargo test -- --test-threads=1
5252
env:
5353
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
54+
- name: Run cargo test (with portable-atomic enabled)
55+
run: cargo test --features portable-atomic
5456
- name: Clone async-executor
5557
run: git clone https://github.com/smol-rs/async-executor.git
5658
- name: Add patch section

Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ exclude = ["/.*"]
1818
default = ["std"]
1919
std = []
2020

21+
[dependencies]
22+
# Uses portable-atomic polyfill atomics on targets without them
23+
portable-atomic = { version = "1", optional = true, default-features = false }
24+
2125
[dev-dependencies]
2226
atomic-waker = "1"
2327
easy-parallel = "3"

src/header.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
use core::cell::UnsafeCell;
22
use core::fmt;
3-
use core::sync::atomic::{AtomicUsize, Ordering};
43
use core::task::Waker;
54

5+
#[cfg(not(feature = "portable-atomic"))]
6+
use core::sync::atomic::AtomicUsize;
7+
use core::sync::atomic::Ordering;
8+
#[cfg(feature = "portable-atomic")]
9+
use portable_atomic::AtomicUsize;
10+
611
use crate::raw::TaskVTable;
712
use crate::state::*;
813
use crate::utils::abort_on_panic;

src/raw.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,14 @@ use core::marker::PhantomData;
55
use core::mem::{self, ManuallyDrop};
66
use core::pin::Pin;
77
use core::ptr::NonNull;
8-
use core::sync::atomic::{AtomicUsize, Ordering};
98
use core::task::{Context, Poll, RawWaker, RawWakerVTable, Waker};
109

10+
#[cfg(not(feature = "portable-atomic"))]
11+
use core::sync::atomic::AtomicUsize;
12+
use core::sync::atomic::Ordering;
13+
#[cfg(feature = "portable-atomic")]
14+
use portable_atomic::AtomicUsize;
15+
1116
use crate::header::Header;
1217
use crate::runnable::{Schedule, ScheduleInfo};
1318
use crate::state::*;

0 commit comments

Comments
 (0)