|
@@ -1,11 +1,11 @@
|
|
|
-use crate::prelude::*;
|
|
|
|
|
|
|
+use crate::{kernel::task::block_on, prelude::*};
|
|
|
use alloc::sync::Arc;
|
|
use alloc::sync::Arc;
|
|
|
use core::{
|
|
use core::{
|
|
|
ops::Deref,
|
|
ops::Deref,
|
|
|
ptr::NonNull,
|
|
ptr::NonNull,
|
|
|
sync::atomic::{AtomicPtr, Ordering},
|
|
sync::atomic::{AtomicPtr, Ordering},
|
|
|
};
|
|
};
|
|
|
-use eonix_runtime::task::Task;
|
|
|
|
|
|
|
+use eonix_runtime::scheduler::RUNTIME;
|
|
|
use eonix_sync::{Mutex, RwLock, RwLockReadGuard};
|
|
use eonix_sync::{Mutex, RwLock, RwLockReadGuard};
|
|
|
use pointers::BorrowedArc;
|
|
use pointers::BorrowedArc;
|
|
|
|
|
|
|
@@ -21,7 +21,7 @@ impl<'data, T> RCUReadGuard<'data, BorrowedArc<'data, T>> {
|
|
|
fn lock(value: BorrowedArc<'data, T>) -> Self {
|
|
fn lock(value: BorrowedArc<'data, T>) -> Self {
|
|
|
Self {
|
|
Self {
|
|
|
value,
|
|
value,
|
|
|
- _guard: Task::block_on(GLOBAL_RCU_SEM.read()),
|
|
|
|
|
|
|
+ _guard: block_on(GLOBAL_RCU_SEM.read()),
|
|
|
_phantom: PhantomData,
|
|
_phantom: PhantomData,
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -48,6 +48,14 @@ pub async fn rcu_sync() {
|
|
|
let _ = GLOBAL_RCU_SEM.write().await;
|
|
let _ = GLOBAL_RCU_SEM.write().await;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+pub fn call_rcu(func: impl FnOnce() + Send + 'static) {
|
|
|
|
|
+ RUNTIME.spawn(async move {
|
|
|
|
|
+ // Wait for all readers to finish.
|
|
|
|
|
+ rcu_sync().await;
|
|
|
|
|
+ func();
|
|
|
|
|
+ });
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
pub trait RCUNode<MySelf> {
|
|
pub trait RCUNode<MySelf> {
|
|
|
fn rcu_prev(&self) -> &AtomicPtr<MySelf>;
|
|
fn rcu_prev(&self) -> &AtomicPtr<MySelf>;
|
|
|
fn rcu_next(&self) -> &AtomicPtr<MySelf>;
|
|
fn rcu_next(&self) -> &AtomicPtr<MySelf>;
|
|
@@ -154,7 +162,7 @@ impl<T: RCUNode<T>> RCUList<T> {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
pub fn iter(&self) -> RCUIterator<T> {
|
|
pub fn iter(&self) -> RCUIterator<T> {
|
|
|
- let _lck = Task::block_on(self.reader_lock.read());
|
|
|
|
|
|
|
+ let _lck = block_on(self.reader_lock.read());
|
|
|
|
|
|
|
|
RCUIterator {
|
|
RCUIterator {
|
|
|
// SAFETY: We have a read lock, so the node is still alive.
|
|
// SAFETY: We have a read lock, so the node is still alive.
|
|
@@ -264,7 +272,10 @@ impl<T> Drop for RCUPointer<T> {
|
|
|
if let Some(arc) = unsafe { self.swap(None) } {
|
|
if let Some(arc) = unsafe { self.swap(None) } {
|
|
|
// We only wait if there are other references.
|
|
// We only wait if there are other references.
|
|
|
if Arc::strong_count(&arc) == 1 {
|
|
if Arc::strong_count(&arc) == 1 {
|
|
|
- Task::block_on(rcu_sync());
|
|
|
|
|
|
|
+ call_rcu(move || {
|
|
|
|
|
+ let _ = arc;
|
|
|
|
|
+ todo!();
|
|
|
|
|
+ });
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|