mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-23 17:33:23 +00:00
Fix infinite waiting of range locks
This commit is contained in:
committed by
Tate, Hongliang Tian
parent
00d9b01d5c
commit
be8cc24544
@ -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(())
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user