net: remove atomic-polyfill.
This commit is contained in:
parent
c283e2d1b9
commit
32b89eeba1
@ -15,7 +15,6 @@ embassy-time = { version = "0.1.3", path = "../embassy-time"}
|
||||
embassy-sync = { version = "0.3.0", path = "../embassy-sync"}
|
||||
embassy-futures = { version = "0.1.0", path = "../embassy-futures"}
|
||||
embassy-net-driver-channel = { version = "0.1.0", path = "../embassy-net-driver-channel"}
|
||||
atomic-polyfill = "0.1.5"
|
||||
|
||||
defmt = { version = "0.3", optional = true }
|
||||
log = { version = "0.4.17", optional = true }
|
||||
|
@ -64,4 +64,3 @@ 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"
|
||||
embedded-nal-async = { version = "0.6.0", optional = true }
|
||||
atomic-polyfill = { version = "1.0" }
|
||||
|
@ -579,11 +579,10 @@ mod embedded_io_impls {
|
||||
/// TCP client compatible with `embedded-nal-async` traits.
|
||||
#[cfg(feature = "nightly")]
|
||||
pub mod client {
|
||||
use core::cell::UnsafeCell;
|
||||
use core::cell::{Cell, UnsafeCell};
|
||||
use core::mem::MaybeUninit;
|
||||
use core::ptr::NonNull;
|
||||
|
||||
use atomic_polyfill::{AtomicBool, Ordering};
|
||||
use embedded_nal_async::IpAddr;
|
||||
|
||||
use super::*;
|
||||
@ -702,15 +701,13 @@ pub mod client {
|
||||
}
|
||||
}
|
||||
|
||||
unsafe impl<const N: usize, const TX_SZ: usize, const RX_SZ: usize> Sync for TcpClientState<N, TX_SZ, RX_SZ> {}
|
||||
|
||||
struct Pool<T, const N: usize> {
|
||||
used: [AtomicBool; N],
|
||||
used: [Cell<bool>; N],
|
||||
data: [UnsafeCell<MaybeUninit<T>>; N],
|
||||
}
|
||||
|
||||
impl<T, const N: usize> Pool<T, N> {
|
||||
const VALUE: AtomicBool = AtomicBool::new(false);
|
||||
const VALUE: Cell<bool> = Cell::new(false);
|
||||
const UNINIT: UnsafeCell<MaybeUninit<T>> = UnsafeCell::new(MaybeUninit::uninit());
|
||||
|
||||
const fn new() -> Self {
|
||||
@ -724,7 +721,9 @@ pub mod client {
|
||||
impl<T, const N: usize> Pool<T, N> {
|
||||
fn alloc(&self) -> Option<NonNull<T>> {
|
||||
for n in 0..N {
|
||||
if self.used[n].swap(true, Ordering::SeqCst) == false {
|
||||
// this can't race because Pool is not Sync.
|
||||
if !self.used[n].get() {
|
||||
self.used[n].set(true);
|
||||
let p = self.data[n].get() as *mut T;
|
||||
return Some(unsafe { NonNull::new_unchecked(p) });
|
||||
}
|
||||
@ -738,7 +737,7 @@ pub mod client {
|
||||
let n = p.as_ptr().offset_from(origin);
|
||||
assert!(n >= 0);
|
||||
assert!((n as usize) < N);
|
||||
self.used[n as usize].store(false, Ordering::SeqCst);
|
||||
self.used[n as usize].set(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -105,8 +105,8 @@ async fn main(spawner: Spawner) -> ! {
|
||||
|
||||
info!("Network task initialized");
|
||||
|
||||
static STATE: TcpClientState<1, 1024, 1024> = TcpClientState::new();
|
||||
let client = TcpClient::new(&stack, &STATE);
|
||||
let state: TcpClientState<1, 1024, 1024> = TcpClientState::new();
|
||||
let client = TcpClient::new(&stack, &state);
|
||||
|
||||
loop {
|
||||
let addr = SocketAddr::V4(SocketAddrV4::new(Ipv4Addr::new(10, 42, 0, 1), 8000));
|
||||
|
Loading…
Reference in New Issue
Block a user