Fix UB in the locking code of context switching

The spin crate considers it UB to call force_write_unlock while there is
a threads trying to obtain a read lock on the same rwlock.

This also switches to the spinning_lot crate for the context rwlock as
it has support for a write guard keeping a reference to the rwlock using
an Arc instead of a reference.
This commit is contained in:
bjorn3
2024-02-25 17:07:41 +01:00
parent 449abb8925
commit 782ec87f27
9 changed files with 68 additions and 56 deletions
+3 -2
View File
@@ -1,11 +1,12 @@
use alloc::{sync::Arc, vec::Vec};
use spin::{Mutex, MutexGuard, RwLock};
use spin::{Mutex, MutexGuard};
use spinning_top::RwSpinlock;
use crate::context::{self, Context};
#[derive(Debug)]
pub struct WaitCondition {
contexts: Mutex<Vec<Arc<RwLock<Context>>>>,
contexts: Mutex<Vec<Arc<RwSpinlock<Context>>>>,
}
impl WaitCondition {