Compare commits
No commits in common. "39f672dde86bed989b29d083fd7409b927d6b18f" and "bb09d253784639e6f783118ee1c5e3666bcd6468" have entirely different histories.
39f672dde8
...
bb09d25378
|
@ -30,7 +30,7 @@ impl Sockets {
|
||||||
let sockets = RefCell::new(SocketSet::new(sockets_storage));
|
let sockets = RefCell::new(SocketSet::new(sockets_storage));
|
||||||
|
|
||||||
let wakers = RefCell::new(Vec::new());
|
let wakers = RefCell::new(Vec::new());
|
||||||
|
|
||||||
let instance = Sockets {
|
let instance = Sockets {
|
||||||
sockets,
|
sockets,
|
||||||
wakers,
|
wakers,
|
||||||
|
@ -57,7 +57,7 @@ impl Sockets {
|
||||||
pub(crate) fn instance() -> &'static Self {
|
pub(crate) fn instance() -> &'static Self {
|
||||||
unsafe { SOCKETS.as_ref().expect("Sockets") }
|
unsafe { SOCKETS.as_ref().expect("Sockets") }
|
||||||
}
|
}
|
||||||
|
|
||||||
fn poll<'b, 'c, 'e, D: for<'d> Device<'d>>(
|
fn poll<'b, 'c, 'e, D: for<'d> Device<'d>>(
|
||||||
&self,
|
&self,
|
||||||
iface: &mut EthernetInterface<'b, 'c, 'e, D>,
|
iface: &mut EthernetInterface<'b, 'c, 'e, D>,
|
||||||
|
@ -81,14 +81,7 @@ impl Sockets {
|
||||||
/// TODO: this was called through eg. TcpStream, another poll()
|
/// TODO: this was called through eg. TcpStream, another poll()
|
||||||
/// might want to send packets before sleeping for an interrupt.
|
/// might want to send packets before sleeping for an interrupt.
|
||||||
pub(crate) fn register_waker(waker: Waker) {
|
pub(crate) fn register_waker(waker: Waker) {
|
||||||
let mut wakers = Self::instance().wakers.borrow_mut();
|
Self::instance().wakers.borrow_mut()
|
||||||
for (i, w) in wakers.iter().enumerate() {
|
.push(waker);
|
||||||
if w.will_wake(&waker) {
|
|
||||||
let last = wakers.len() - 1;
|
|
||||||
wakers.swap(i, last);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
wakers.push(waker);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@ use core::sync::atomic::{AtomicU32, Ordering};
|
||||||
use core::cell::UnsafeCell;
|
use core::cell::UnsafeCell;
|
||||||
use super::{
|
use super::{
|
||||||
spin_lock_yield, notify_spin_lock,
|
spin_lock_yield, notify_spin_lock,
|
||||||
asm::{enter_critical, exit_critical}
|
asm::{dmb, enter_critical, exit_critical}
|
||||||
};
|
};
|
||||||
|
|
||||||
const LOCKED: u32 = 1;
|
const LOCKED: u32 = 1;
|
||||||
|
@ -32,27 +32,30 @@ impl<T> Mutex<T> {
|
||||||
/// Lock the Mutex, blocks when already locked
|
/// Lock the Mutex, blocks when already locked
|
||||||
pub fn lock(&self) -> MutexGuard<T> {
|
pub fn lock(&self) -> MutexGuard<T> {
|
||||||
let mut irq = unsafe { enter_critical() };
|
let mut irq = unsafe { enter_critical() };
|
||||||
while self.locked.compare_and_swap(UNLOCKED, LOCKED, Ordering::AcqRel) != UNLOCKED {
|
while self.locked.compare_and_swap(UNLOCKED, LOCKED, Ordering::Acquire) != UNLOCKED {
|
||||||
unsafe {
|
unsafe {
|
||||||
exit_critical(irq);
|
exit_critical(irq);
|
||||||
spin_lock_yield();
|
spin_lock_yield();
|
||||||
irq = enter_critical();
|
irq = enter_critical();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
dmb();
|
||||||
MutexGuard { mutex: self, irq }
|
MutexGuard { mutex: self, irq }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn try_lock(&self) -> Option<MutexGuard<T>> {
|
pub fn try_lock(&self) -> Option<MutexGuard<T>> {
|
||||||
let irq = unsafe { enter_critical() };
|
let irq = unsafe { enter_critical() };
|
||||||
if self.locked.compare_and_swap(UNLOCKED, LOCKED, Ordering::AcqRel) != UNLOCKED {
|
if self.locked.compare_and_swap(UNLOCKED, LOCKED, Ordering::Acquire) != UNLOCKED {
|
||||||
unsafe { exit_critical(irq) };
|
unsafe { exit_critical(irq) };
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
|
dmb();
|
||||||
Some(MutexGuard { mutex: self, irq })
|
Some(MutexGuard { mutex: self, irq })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn unlock(&self) {
|
fn unlock(&self) {
|
||||||
|
dmb();
|
||||||
self.locked.store(UNLOCKED, Ordering::Release);
|
self.locked.store(UNLOCKED, Ordering::Release);
|
||||||
|
|
||||||
notify_spin_lock();
|
notify_spin_lock();
|
||||||
|
|
Loading…
Reference in New Issue