Solve borrow checking by downgrading waitqueue lock
This commit is contained in:
@@ -6,8 +6,8 @@ use alloc::{
|
||||
};
|
||||
|
||||
use crate::{
|
||||
context::{self, ContextLock, PreemptGuard, PreemptGuardL1},
|
||||
sync::{CleanLockToken, LockToken, Mutex, L1, L3},
|
||||
context::{self, ContextLock, PreemptGuard, PreemptGuardL1, PreemptGuardL2},
|
||||
sync::{CleanLockToken, LockToken, Mutex, L1, L2, L3},
|
||||
};
|
||||
|
||||
#[derive(Debug)]
|
||||
@@ -59,6 +59,16 @@ impl WaitCondition {
|
||||
guard: T,
|
||||
reason: &'static str,
|
||||
token: &'a mut LockToken<'a, L1>,
|
||||
) -> bool {
|
||||
let mut token = token.downgrade();
|
||||
self.wait_inner(guard, reason, &mut token)
|
||||
}
|
||||
|
||||
pub fn wait_inner<'a, T>(
|
||||
&self,
|
||||
guard: T,
|
||||
reason: &'static str,
|
||||
token: &'a mut LockToken<'a, L2>,
|
||||
) -> bool {
|
||||
let current_context_ref = context::current();
|
||||
{
|
||||
@@ -67,7 +77,7 @@ impl WaitCondition {
|
||||
// We cannot add ourselves to the wait list first as that would lead
|
||||
// to deadlock if we were woken up immediately.
|
||||
let mut token = token.token();
|
||||
let mut preempt = PreemptGuardL1::new(¤t_context_ref, &mut token);
|
||||
let mut preempt = PreemptGuardL2::new(¤t_context_ref, &mut token);
|
||||
let token = preempt.token();
|
||||
{
|
||||
let mut context = current_context_ref.write(token.token());
|
||||
|
||||
@@ -2,7 +2,7 @@ use alloc::collections::VecDeque;
|
||||
use syscall::{EAGAIN, EINTR};
|
||||
|
||||
use crate::{
|
||||
sync::{CleanLockToken, LockToken, Mutex, WaitCondition, L1},
|
||||
sync::{CleanLockToken, LockToken, Mutex, WaitCondition, L1, L2},
|
||||
syscall::{
|
||||
error::{Error, Result, EINVAL},
|
||||
usercopy::UserSliceWo,
|
||||
@@ -11,7 +11,7 @@ use crate::{
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct WaitQueue<T> {
|
||||
inner: Mutex<L1, VecDeque<T>>,
|
||||
inner: Mutex<L2, VecDeque<T>>,
|
||||
pub condition: WaitCondition,
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ impl<T> WaitQueue<T> {
|
||||
|
||||
if inner.is_empty() {
|
||||
if block {
|
||||
if !self.condition.wait(inner, reason, &mut token) {
|
||||
if !self.condition.wait_inner(inner, reason, &mut token) {
|
||||
return Err(Error::new(EINTR));
|
||||
}
|
||||
continue;
|
||||
|
||||
Reference in New Issue
Block a user