From 10c9cc31b14a356e58833fd6c81456251ab3fce9 Mon Sep 17 00:00:00 2001 From: Dario Nieuwenhuis Date: Fri, 23 Dec 2022 20:46:49 +0100 Subject: [PATCH] Remove unnecessary use of atomic-polyfill. Only use it when CAS is actually needed. --- .vscode/settings.json | 11 ++++++----- embassy-executor/src/arch/riscv32.rs | 3 +-- embassy-executor/src/arch/xtensa.rs | 3 +-- embassy-net/Cargo.toml | 1 - embassy-net/src/tcp.rs | 2 +- embassy-rp/src/multicore.rs | 4 +--- embassy-rp/src/usb.rs | 3 +-- embassy-stm32/src/adc/v4.rs | 3 ++- embassy-stm32/src/flash/f4.rs | 3 +-- embassy-stm32/src/flash/f7.rs | 3 +-- embassy-stm32/src/flash/h7.rs | 4 ++-- embassy-stm32/src/i2c/v2.rs | 5 +++-- embassy-stm32/src/usart/buffered.rs | 2 +- embassy-stm32/src/usart/mod.rs | 2 +- embassy-sync/Cargo.toml | 1 - 15 files changed, 22 insertions(+), 28 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 62e5a362..fd2e4afb 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -4,7 +4,8 @@ "rust-analyzer.checkOnSave.noDefaultFeatures": true, "rust-analyzer.cargo.noDefaultFeatures": true, "rust-analyzer.procMacro.enable": true, - "rust-analyzer.cargo.target": "thumbv7em-none-eabi", + //"rust-analyzer.cargo.target": "thumbv7em-none-eabi", + "rust-analyzer.cargo.target": "thumbv8m.main-none-eabihf", "rust-analyzer.cargo.features": [ // These are needed to prevent embassy-net from failing to build //"embassy-net/medium-ethernet", @@ -12,19 +13,19 @@ //"embassy-net/pool-16", //"time-tick-16mhz", //"defmt-timestamp-uptime", - "nightly", + //"nightly", //"unstable-traits", ], "rust-analyzer.linkedProjects": [ // Declare for the target you wish to develop //"embassy-executor/Cargo.toml", //"embassy-sync/Cargo.toml", - "examples/nrf/Cargo.toml", + //"examples/nrf/Cargo.toml", // "examples/nrf-rtos-trace/Cargo.toml", // "examples/rp/Cargo.toml", // "examples/std/Cargo.toml", // "examples/stm32f0/Cargo.toml", - // "examples/stm32f1/Cargo.toml", + //"examples/stm32f1/Cargo.toml", // "examples/stm32f2/Cargo.toml", // "examples/stm32f3/Cargo.toml", // "examples/stm32f4/Cargo.toml", @@ -35,7 +36,7 @@ // "examples/stm32l0/Cargo.toml", // "examples/stm32l1/Cargo.toml", // "examples/stm32l4/Cargo.toml", - // "examples/stm32l5/Cargo.toml", + "examples/stm32l5/Cargo.toml", // "examples/stm32u5/Cargo.toml", // "examples/stm32wb/Cargo.toml", // "examples/stm32wb55/Cargo.toml", diff --git a/embassy-executor/src/arch/riscv32.rs b/embassy-executor/src/arch/riscv32.rs index 2a4b006d..e97a56cd 100644 --- a/embassy-executor/src/arch/riscv32.rs +++ b/embassy-executor/src/arch/riscv32.rs @@ -1,7 +1,6 @@ use core::marker::PhantomData; use core::ptr; - -use atomic_polyfill::{AtomicBool, Ordering}; +use core::sync::atomic::{AtomicBool, Ordering}; use super::{raw, Spawner}; diff --git a/embassy-executor/src/arch/xtensa.rs b/embassy-executor/src/arch/xtensa.rs index f908aaa7..4ee0d9f7 100644 --- a/embassy-executor/src/arch/xtensa.rs +++ b/embassy-executor/src/arch/xtensa.rs @@ -1,7 +1,6 @@ use core::marker::PhantomData; use core::ptr; - -use atomic_polyfill::{AtomicBool, Ordering}; +use core::sync::atomic::{AtomicBool, Ordering}; use super::{raw, Spawner}; diff --git a/embassy-net/Cargo.toml b/embassy-net/Cargo.toml index ac338843..2d853762 100644 --- a/embassy-net/Cargo.toml +++ b/embassy-net/Cargo.toml @@ -51,7 +51,6 @@ generic-array = { version = "0.14.4", default-features = false } stable_deref_trait = { version = "1.2.0", default-features = false } futures = { version = "0.3.17", default-features = false, features = [ "async-await" ] } atomic-pool = "1.0" -atomic-polyfill = "1.0.1" embedded-nal-async = { version = "0.3.0", optional = true } [dependencies.smoltcp] diff --git a/embassy-net/src/tcp.rs b/embassy-net/src/tcp.rs index 0dc8da73..55cbda45 100644 --- a/embassy-net/src/tcp.rs +++ b/embassy-net/src/tcp.rs @@ -329,8 +329,8 @@ pub mod client { use core::cell::UnsafeCell; use core::mem::MaybeUninit; use core::ptr::NonNull; + use core::sync::atomic::{AtomicBool, Ordering}; - use atomic_polyfill::{AtomicBool, Ordering}; use embedded_nal_async::IpAddr; use super::*; diff --git a/embassy-rp/src/multicore.rs b/embassy-rp/src/multicore.rs index 8290c62a..e51fc218 100644 --- a/embassy-rp/src/multicore.rs +++ b/embassy-rp/src/multicore.rs @@ -29,9 +29,7 @@ //! ``` use core::mem::ManuallyDrop; -use core::sync::atomic::{compiler_fence, Ordering}; - -use atomic_polyfill::AtomicBool; +use core::sync::atomic::{compiler_fence, AtomicBool, Ordering}; use crate::interrupt::{Interrupt, InterruptExt}; use crate::peripherals::CORE1; diff --git a/embassy-rp/src/usb.rs b/embassy-rp/src/usb.rs index dfc2e9da..8361736a 100644 --- a/embassy-rp/src/usb.rs +++ b/embassy-rp/src/usb.rs @@ -1,10 +1,9 @@ use core::future::poll_fn; use core::marker::PhantomData; use core::slice; -use core::sync::atomic::Ordering; +use core::sync::atomic::{compiler_fence, Ordering}; use core::task::Poll; -use atomic_polyfill::compiler_fence; use embassy_hal_common::into_ref; use embassy_sync::waitqueue::AtomicWaker; use embassy_usb_driver as driver; diff --git a/embassy-stm32/src/adc/v4.rs b/embassy-stm32/src/adc/v4.rs index f5aa0e63..4707b7c9 100644 --- a/embassy-stm32/src/adc/v4.rs +++ b/embassy-stm32/src/adc/v4.rs @@ -1,4 +1,5 @@ -use atomic_polyfill::{AtomicU8, Ordering}; +use core::sync::atomic::{AtomicU8, Ordering}; + use embedded_hal_02::blocking::delay::DelayUs; use pac::adc::vals::{Adcaldif, Boost, Difsel, Exten, Pcsel}; use pac::adccommon::vals::Presc; diff --git a/embassy-stm32/src/flash/f4.rs b/embassy-stm32/src/flash/f4.rs index b8327ce4..9e23a8ad 100644 --- a/embassy-stm32/src/flash/f4.rs +++ b/embassy-stm32/src/flash/f4.rs @@ -1,7 +1,6 @@ use core::convert::TryInto; use core::ptr::write_volatile; - -use atomic_polyfill::{fence, Ordering}; +use core::sync::atomic::{fence, Ordering}; use super::{ERASE_SIZE, FLASH_BASE, FLASH_SIZE}; use crate::flash::Error; diff --git a/embassy-stm32/src/flash/f7.rs b/embassy-stm32/src/flash/f7.rs index 6d47b78a..dd0d8439 100644 --- a/embassy-stm32/src/flash/f7.rs +++ b/embassy-stm32/src/flash/f7.rs @@ -1,7 +1,6 @@ use core::convert::TryInto; use core::ptr::write_volatile; - -use atomic_polyfill::{fence, Ordering}; +use core::sync::atomic::{fence, Ordering}; use crate::flash::Error; use crate::pac; diff --git a/embassy-stm32/src/flash/h7.rs b/embassy-stm32/src/flash/h7.rs index 3178b3be..7de95ac1 100644 --- a/embassy-stm32/src/flash/h7.rs +++ b/embassy-stm32/src/flash/h7.rs @@ -41,7 +41,7 @@ pub(crate) unsafe fn blocking_write(offset: u32, buf: &[u8]) -> Result<(), Error cortex_m::asm::isb(); cortex_m::asm::dsb(); - atomic_polyfill::fence(atomic_polyfill::Ordering::SeqCst); + core::sync::atomic::fence(core::sync::atomic::Ordering::SeqCst); let ret = { let mut ret: Result<(), Error> = Ok(()); @@ -70,7 +70,7 @@ pub(crate) unsafe fn blocking_write(offset: u32, buf: &[u8]) -> Result<(), Error cortex_m::asm::isb(); cortex_m::asm::dsb(); - atomic_polyfill::fence(atomic_polyfill::Ordering::SeqCst); + core::sync::atomic::fence(core::sync::atomic::Ordering::SeqCst); ret } diff --git a/embassy-stm32/src/i2c/v2.rs b/embassy-stm32/src/i2c/v2.rs index 47dc7d2a..4622635b 100644 --- a/embassy-stm32/src/i2c/v2.rs +++ b/embassy-stm32/src/i2c/v2.rs @@ -1,8 +1,8 @@ use core::cmp; use core::future::poll_fn; +use core::sync::atomic::{AtomicUsize, Ordering}; use core::task::Poll; -use atomic_polyfill::{AtomicUsize, Ordering}; use embassy_embedded_hal::SetConfig; use embassy_hal_common::drop::OnDrop; use embassy_hal_common::{into_ref, PeripheralRef}; @@ -131,7 +131,8 @@ impl<'d, T: Instance, TXDMA, RXDMA> I2c<'d, T, TXDMA, RXDMA> { if isr.tcr() || isr.tc() { let state = T::state(); - state.chunks_transferred.fetch_add(1, Ordering::Relaxed); + let transferred = state.chunks_transferred.load(Ordering::Relaxed); + state.chunks_transferred.store(transferred + 1, Ordering::Relaxed); state.waker.wake(); } // The flag can only be cleared by writting to nbytes, we won't do that here, so disable diff --git a/embassy-stm32/src/usart/buffered.rs b/embassy-stm32/src/usart/buffered.rs index 874af1d7..a27fcc1c 100644 --- a/embassy-stm32/src/usart/buffered.rs +++ b/embassy-stm32/src/usart/buffered.rs @@ -1,8 +1,8 @@ use core::cell::RefCell; use core::future::poll_fn; +use core::sync::atomic::{compiler_fence, Ordering}; use core::task::Poll; -use atomic_polyfill::{compiler_fence, Ordering}; use embassy_cortex_m::peripheral::{PeripheralMutex, PeripheralState, StateStorage}; use embassy_hal_common::ring_buffer::RingBuffer; use embassy_sync::waitqueue::WakerRegistration; diff --git a/embassy-stm32/src/usart/mod.rs b/embassy-stm32/src/usart/mod.rs index ea75361f..6f8b6a9e 100644 --- a/embassy-stm32/src/usart/mod.rs +++ b/embassy-stm32/src/usart/mod.rs @@ -2,9 +2,9 @@ use core::future::poll_fn; use core::marker::PhantomData; +use core::sync::atomic::{compiler_fence, Ordering}; use core::task::Poll; -use atomic_polyfill::{compiler_fence, Ordering}; use embassy_cortex_m::interrupt::InterruptExt; use embassy_futures::select::{select, Either}; use embassy_hal_common::drop::OnDrop; diff --git a/embassy-sync/Cargo.toml b/embassy-sync/Cargo.toml index 1eeb94c9..7b5d3ce4 100644 --- a/embassy-sync/Cargo.toml +++ b/embassy-sync/Cargo.toml @@ -31,7 +31,6 @@ defmt = { version = "0.3", optional = true } log = { version = "0.4.14", optional = true } futures-util = { version = "0.3.17", default-features = false } -atomic-polyfill = "1.0.1" critical-section = "1.1" heapless = "0.7.5" cfg-if = "1.0.0"