Protect socket states with PreemptDisabled

This commit is contained in:
Ruihan Li
2024-12-08 16:25:34 +08:00
committed by Tate, Hongliang Tian
parent 39a5e88baf
commit 1207161afe
3 changed files with 9 additions and 9 deletions

View File

@ -8,7 +8,7 @@ use connecting::{ConnResult, ConnectingStream};
use init::InitStream;
use listen::ListenStream;
use options::{Congestion, MaxSegment, NoDelay, WindowClamp};
use ostd::sync::{PreemptDisabled, RwLockReadGuard, RwLockWriteGuard, WriteIrqDisabled};
use ostd::sync::{PreemptDisabled, RwLockReadGuard, RwLockWriteGuard};
use takeable::Takeable;
use util::TcpOptionSet;
@ -46,7 +46,7 @@ pub use self::util::CongestionControl;
pub struct StreamSocket {
options: RwLock<OptionSet>,
state: RwLock<Takeable<State>, WriteIrqDisabled>,
state: RwLock<Takeable<State>, PreemptDisabled>,
is_nonblocking: AtomicBool,
pollee: Pollee,
}
@ -109,7 +109,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>, WriteIrqDisabled> {
fn read_updated_state(&self) -> RwLockReadGuard<Takeable<State>, PreemptDisabled> {
loop {
let state = self.state.read();
match state.as_ref() {
@ -125,7 +125,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>, WriteIrqDisabled> {
fn write_updated_state(&self) -> RwLockWriteGuard<Takeable<State>, PreemptDisabled> {
self.update_connecting().1
}
@ -142,7 +142,7 @@ impl StreamSocket {
&self,
) -> (
RwLockWriteGuard<OptionSet, PreemptDisabled>,
RwLockWriteGuard<Takeable<State>, WriteIrqDisabled>,
RwLockWriteGuard<Takeable<State>, PreemptDisabled>,
) {
// Hold the lock in advance to avoid race conditions.
let mut options = self.options.write();