aboutsummaryrefslogtreecommitdiff
path: root/embassy-net
diff options
context:
space:
mode:
authorDario Nieuwenhuis <[email protected]>2023-10-12 01:35:23 +0200
committerDario Nieuwenhuis <[email protected]>2023-10-12 02:07:26 +0200
commit32b89eeba18d2d0a9c3705212768d4ade3f4948d (patch)
treef81252e96ad42ec4f4808ecf41024080a20d265f /embassy-net
parentc283e2d1b914b58459bd39f59c2bda0e55d5d0bd (diff)
net: remove atomic-polyfill.
Diffstat (limited to 'embassy-net')
-rw-r--r--embassy-net/Cargo.toml1
-rw-r--r--embassy-net/src/tcp.rs15
2 files changed, 7 insertions, 9 deletions
diff --git a/embassy-net/Cargo.toml b/embassy-net/Cargo.toml
index c2fffba84..a3c18046e 100644
--- a/embassy-net/Cargo.toml
+++ b/embassy-net/Cargo.toml
@@ -64,4 +64,3 @@ stable_deref_trait = { version = "1.2.0", default-features = false }
64futures = { version = "0.3.17", default-features = false, features = [ "async-await" ] } 64futures = { version = "0.3.17", default-features = false, features = [ "async-await" ] }
65atomic-pool = "1.0" 65atomic-pool = "1.0"
66embedded-nal-async = { version = "0.6.0", optional = true } 66embedded-nal-async = { version = "0.6.0", optional = true }
67atomic-polyfill = { version = "1.0" }
diff --git a/embassy-net/src/tcp.rs b/embassy-net/src/tcp.rs
index a12fd382a..b5615cb66 100644
--- a/embassy-net/src/tcp.rs
+++ b/embassy-net/src/tcp.rs
@@ -579,11 +579,10 @@ mod embedded_io_impls {
579/// TCP client compatible with `embedded-nal-async` traits. 579/// TCP client compatible with `embedded-nal-async` traits.
580#[cfg(feature = "nightly")] 580#[cfg(feature = "nightly")]
581pub mod client { 581pub mod client {
582 use core::cell::UnsafeCell; 582 use core::cell::{Cell, UnsafeCell};
583 use core::mem::MaybeUninit; 583 use core::mem::MaybeUninit;
584 use core::ptr::NonNull; 584 use core::ptr::NonNull;
585 585
586 use atomic_polyfill::{AtomicBool, Ordering};
587 use embedded_nal_async::IpAddr; 586 use embedded_nal_async::IpAddr;
588 587
589 use super::*; 588 use super::*;
@@ -702,15 +701,13 @@ pub mod client {
702 } 701 }
703 } 702 }
704 703
705 unsafe impl<const N: usize, const TX_SZ: usize, const RX_SZ: usize> Sync for TcpClientState<N, TX_SZ, RX_SZ> {}
706
707 struct Pool<T, const N: usize> { 704 struct Pool<T, const N: usize> {
708 used: [AtomicBool; N], 705 used: [Cell<bool>; N],
709 data: [UnsafeCell<MaybeUninit<T>>; N], 706 data: [UnsafeCell<MaybeUninit<T>>; N],
710 } 707 }
711 708
712 impl<T, const N: usize> Pool<T, N> { 709 impl<T, const N: usize> Pool<T, N> {
713 const VALUE: AtomicBool = AtomicBool::new(false); 710 const VALUE: Cell<bool> = Cell::new(false);
714 const UNINIT: UnsafeCell<MaybeUninit<T>> = UnsafeCell::new(MaybeUninit::uninit()); 711 const UNINIT: UnsafeCell<MaybeUninit<T>> = UnsafeCell::new(MaybeUninit::uninit());
715 712
716 const fn new() -> Self { 713 const fn new() -> Self {
@@ -724,7 +721,9 @@ pub mod client {
724 impl<T, const N: usize> Pool<T, N> { 721 impl<T, const N: usize> Pool<T, N> {
725 fn alloc(&self) -> Option<NonNull<T>> { 722 fn alloc(&self) -> Option<NonNull<T>> {
726 for n in 0..N { 723 for n in 0..N {
727 if self.used[n].swap(true, Ordering::SeqCst) == false { 724 // this can't race because Pool is not Sync.
725 if !self.used[n].get() {
726 self.used[n].set(true);
728 let p = self.data[n].get() as *mut T; 727 let p = self.data[n].get() as *mut T;
729 return Some(unsafe { NonNull::new_unchecked(p) }); 728 return Some(unsafe { NonNull::new_unchecked(p) });
730 } 729 }
@@ -738,7 +737,7 @@ pub mod client {
738 let n = p.as_ptr().offset_from(origin); 737 let n = p.as_ptr().offset_from(origin);
739 assert!(n >= 0); 738 assert!(n >= 0);
740 assert!((n as usize) < N); 739 assert!((n as usize) < N);
741 self.used[n as usize].store(false, Ordering::SeqCst); 740 self.used[n as usize].set(false);
742 } 741 }
743 } 742 }
744} 743}