lock ordering

This commit is contained in:
Jeremy Soller
2025-09-22 07:48:48 -06:00
parent e7358e3e5b
commit 5dc6f7c3ba
79 changed files with 2420 additions and 1181 deletions
+12 -6
View File
@@ -3,7 +3,7 @@ use spin::Mutex;
use syscall::{EAGAIN, EINTR};
use crate::{
sync::WaitCondition,
sync::{CleanLockToken, WaitCondition},
syscall::{
error::{Error, Result, EINVAL},
usercopy::UserSliceWo,
@@ -27,7 +27,12 @@ impl<T> WaitQueue<T> {
self.inner.lock().is_empty()
}
pub fn receive(&self, block: bool, reason: &'static str) -> Result<T> {
pub fn receive(
&self,
block: bool,
reason: &'static str,
token: &mut CleanLockToken,
) -> Result<T> {
loop {
let mut inner = self.inner.lock();
@@ -37,7 +42,7 @@ impl<T> WaitQueue<T> {
}
_ => {
if block {
if !self.condition.wait(inner, reason) {
if !self.condition.wait(inner, reason, token) {
return Err(Error::new(EINTR));
}
continue;
@@ -54,13 +59,14 @@ impl<T> WaitQueue<T> {
buf: UserSliceWo,
block: bool,
reason: &'static str,
token: &mut CleanLockToken,
) -> Result<usize> {
loop {
let mut inner = self.inner.lock();
if inner.is_empty() {
if block {
if !self.condition.wait(inner, reason) {
if !self.condition.wait(inner, reason, token) {
return Err(Error::new(EINTR));
}
continue;
@@ -100,13 +106,13 @@ impl<T> WaitQueue<T> {
}
}
pub fn send(&self, value: T) -> usize {
pub fn send(&self, value: T, token: &mut CleanLockToken) -> usize {
let len = {
let mut inner = self.inner.lock();
inner.push_back(value);
inner.len()
};
self.condition.notify();
self.condition.notify(token);
len
}
}