Fix infinite waiting of range locks

This commit is contained in:
Fabing Li
2024-08-22 15:11:43 +08:00
committed by Tate, Hongliang Tian
parent 00d9b01d5c
commit be8cc24544

View File

@ -132,8 +132,10 @@ impl RangeLockItem {
} }
/// Puts the current process in a wait state until the lock condition is satisfied /// Puts the current process in a wait state until the lock condition is satisfied
pub fn wait(&mut self) { pub fn wait_until<F>(&self, cond: F)
let cond = || None::<()>; where
F: FnMut() -> Option<()>,
{
self.waitqueue.wait_until(cond); self.waitqueue.wait_until(cond);
} }
@ -227,7 +229,7 @@ impl RangeLockList {
req_lock, is_nonblocking req_lock, is_nonblocking
); );
loop { loop {
let mut conflict_lock; let conflict_lock;
{ {
let mut list = self.inner.write(); let mut list = self.inner.write();
@ -243,7 +245,14 @@ impl RangeLockList {
} }
} }
conflict_lock.wait(); conflict_lock.wait_until(|| {
let list = self.inner.read();
if list.iter().any(|l| req_lock.conflict_with(l)) {
None
} else {
Some(())
}
});
} }
} }