mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-19 12:36:46 +00:00
Fix socket lock ordering
This commit is contained in:
committed by
Tate, Hongliang Tian
parent
3981cd63cd
commit
a14ac1ccbf
@ -46,10 +46,16 @@ impl IfaceCommon {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Acquires the lock to the interface.
|
||||||
|
///
|
||||||
|
/// *Lock ordering:* [`Self::sockets`] first, [`Self::interface`] second.
|
||||||
pub(super) fn interface(&self) -> SpinLockGuard<smoltcp::iface::Interface> {
|
pub(super) fn interface(&self) -> SpinLockGuard<smoltcp::iface::Interface> {
|
||||||
self.interface.lock_irq_disabled()
|
self.interface.lock_irq_disabled()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Acuqires the lock to the sockets.
|
||||||
|
///
|
||||||
|
/// *Lock ordering:* [`Self::sockets`] first, [`Self::interface`] second.
|
||||||
pub(super) fn sockets(&self) -> SpinLockGuard<smoltcp::iface::SocketSet<'static>> {
|
pub(super) fn sockets(&self) -> SpinLockGuard<smoltcp::iface::SocketSet<'static>> {
|
||||||
self.sockets.lock_irq_disabled()
|
self.sockets.lock_irq_disabled()
|
||||||
}
|
}
|
||||||
@ -148,8 +154,8 @@ impl IfaceCommon {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub(super) fn poll<D: Device + ?Sized>(&self, device: &mut D) {
|
pub(super) fn poll<D: Device + ?Sized>(&self, device: &mut D) {
|
||||||
let mut interface = self.interface.lock_irq_disabled();
|
|
||||||
let mut sockets = self.sockets.lock_irq_disabled();
|
let mut sockets = self.sockets.lock_irq_disabled();
|
||||||
|
let mut interface = self.interface.lock_irq_disabled();
|
||||||
|
|
||||||
let timestamp = get_network_timestamp();
|
let timestamp = get_network_timestamp();
|
||||||
let (has_events, poll_at) = {
|
let (has_events, poll_at) = {
|
||||||
@ -169,8 +175,8 @@ impl IfaceCommon {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// drop sockets here to avoid deadlock
|
// drop sockets here to avoid deadlock
|
||||||
drop(sockets);
|
|
||||||
drop(interface);
|
drop(interface);
|
||||||
|
drop(sockets);
|
||||||
|
|
||||||
if let Some(instant) = poll_at {
|
if let Some(instant) = poll_at {
|
||||||
let old_instant = self.next_poll_at_ms.load(Ordering::Relaxed);
|
let old_instant = self.next_poll_at_ms.load(Ordering::Relaxed);
|
||||||
|
Reference in New Issue
Block a user