Implement WriteIrqDisabled

This commit is contained in:
Ruihan Li
2024-12-03 10:51:11 +08:00
committed by Tate, Hongliang Tian
parent 29659dbc98
commit a260411a2a
7 changed files with 58 additions and 22 deletions

View File

@ -9,7 +9,7 @@ use core::{
sync::atomic::{AtomicBool, AtomicU64, AtomicU8, Ordering},
};
use ostd::sync::{LocalIrqDisabled, RwLock, SpinLock, SpinLockGuard};
use ostd::sync::{LocalIrqDisabled, RwLock, SpinLock, SpinLockGuard, WriteIrqDisabled};
use smoltcp::{
iface::Context,
socket::{tcp::State, udp::UdpMetadata, PollAt},
@ -46,7 +46,7 @@ pub struct BoundSocketInner<T, E> {
iface: Arc<dyn Iface<E>>,
port: u16,
socket: T,
observer: RwLock<Weak<dyn SocketEventObserver>, LocalIrqDisabled>,
observer: RwLock<Weak<dyn SocketEventObserver>, WriteIrqDisabled>,
events: AtomicU8,
next_poll_at_ms: AtomicU64,
}
@ -232,8 +232,6 @@ impl<T: AnySocket, E> BoundSocket<T, E> {
///
/// See also [`Self::set_observer`].
pub fn observer(&self) -> Weak<dyn SocketEventObserver> {
// We never hold the write lock in IRQ handlers, so we don't need to disable IRQs when we
// get the read lock.
self.0.observer.read().clone()
}

View File

@ -6,7 +6,7 @@ use aster_bigtcp::{
socket::{SocketEventObserver, SocketEvents},
wire::IpEndpoint,
};
use ostd::sync::LocalIrqDisabled;
use ostd::sync::WriteIrqDisabled;
use takeable::Takeable;
use self::{bound::BoundDatagram, unbound::UnboundDatagram};
@ -52,7 +52,7 @@ impl OptionSet {
pub struct DatagramSocket {
options: RwLock<OptionSet>,
inner: RwLock<Takeable<Inner>, LocalIrqDisabled>,
inner: RwLock<Takeable<Inner>, WriteIrqDisabled>,
nonblocking: AtomicBool,
pollee: Pollee,
}

View File

@ -3,7 +3,7 @@
use aster_bigtcp::{
errors::tcp::ListenError, iface::BindPortConfig, socket::UnboundTcpSocket, wire::IpEndpoint,
};
use ostd::sync::LocalIrqDisabled;
use ostd::sync::WriteIrqDisabled;
use super::connected::ConnectedStream;
use crate::{
@ -17,7 +17,7 @@ pub struct ListenStream {
/// A bound socket held to ensure the TCP port cannot be released
bound_socket: BoundTcpSocket,
/// Backlog sockets listening at the local endpoint
backlog_sockets: RwLock<Vec<BacklogSocket>, LocalIrqDisabled>,
backlog_sockets: RwLock<Vec<BacklogSocket>, WriteIrqDisabled>,
}
impl ListenStream {

View File

@ -11,7 +11,7 @@ use connecting::{ConnResult, ConnectingStream};
use init::InitStream;
use listen::ListenStream;
use options::{Congestion, MaxSegment, NoDelay, WindowClamp};
use ostd::sync::{LocalIrqDisabled, PreemptDisabled, RwLockReadGuard, RwLockWriteGuard};
use ostd::sync::{PreemptDisabled, RwLockReadGuard, RwLockWriteGuard, WriteIrqDisabled};
use takeable::Takeable;
use util::TcpOptionSet;
@ -50,7 +50,7 @@ pub use self::util::CongestionControl;
pub struct StreamSocket {
options: RwLock<OptionSet>,
state: RwLock<Takeable<State>, LocalIrqDisabled>,
state: RwLock<Takeable<State>, WriteIrqDisabled>,
is_nonblocking: AtomicBool,
pollee: Pollee,
}
@ -116,7 +116,7 @@ impl StreamSocket {
/// Ensures that the socket state is up to date and obtains a read lock on it.
///
/// For a description of what "up-to-date" means, see [`Self::update_connecting`].
fn read_updated_state(&self) -> RwLockReadGuard<Takeable<State>, LocalIrqDisabled> {
fn read_updated_state(&self) -> RwLockReadGuard<Takeable<State>, WriteIrqDisabled> {
loop {
let state = self.state.read();
match state.as_ref() {
@ -132,7 +132,7 @@ impl StreamSocket {
/// Ensures that the socket state is up to date and obtains a write lock on it.
///
/// For a description of what "up-to-date" means, see [`Self::update_connecting`].
fn write_updated_state(&self) -> RwLockWriteGuard<Takeable<State>, LocalIrqDisabled> {
fn write_updated_state(&self) -> RwLockWriteGuard<Takeable<State>, WriteIrqDisabled> {
self.update_connecting().1
}
@ -149,7 +149,7 @@ impl StreamSocket {
&self,
) -> (
RwLockWriteGuard<OptionSet, PreemptDisabled>,
RwLockWriteGuard<Takeable<State>, LocalIrqDisabled>,
RwLockWriteGuard<Takeable<State>, WriteIrqDisabled>,
) {
// Hold the lock in advance to avoid race conditions.
let mut options = self.options.write();