Solve borrow checking by downgrading waitqueue lock

This commit is contained in:
Wildan M
2026-03-11 09:42:06 +07:00
parent f07725682f
commit 84754dfc5d
3 changed files with 41 additions and 7 deletions
+25 -1
View File
@@ -12,7 +12,7 @@ use crate::{
percpu::PercpuBlock,
sync::{
ArcRwLockWriteGuard, CleanLockToken, LockToken, RwLock, RwLockReadGuard, RwLockWriteGuard,
L0, L1, L4,
L0, L1, L2, L4,
},
syscall::error::Result,
};
@@ -234,3 +234,27 @@ impl Drop for PreemptGuardL1<'_> {
self.context.write(self.token.token()).preempt_locks -= 1;
}
}
/// Variant of PreemptGuard behind a one-level token
pub struct PreemptGuardL2<'a> {
context: &'a ContextLock,
token: &'a mut LockToken<'a, L2>,
}
impl<'a> PreemptGuardL2<'a> {
pub fn new(context: &'a ContextLock, token: &'a mut LockToken<'a, L2>) -> PreemptGuardL2<'a> {
context.write(token.token()).preempt_locks += 1;
PreemptGuardL2 { context, token }
}
/// Get a mutable reference to the underlying `LockToken<L2>`.
pub fn token(&mut self) -> &mut LockToken<'a, L2> {
self.token
}
}
impl Drop for PreemptGuardL2<'_> {
fn drop(&mut self) {
self.context.write(self.token.token()).preempt_locks -= 1;
}
}