From e0bda4677cd02dce219de937e36b193796bf4a51 Mon Sep 17 00:00:00 2001 From: Ruihan Li Date: Fri, 11 Apr 2025 16:25:12 +0800 Subject: [PATCH] Remove `Send` trait bound from `NonNullPtr` --- ostd/src/sync/rcu/mod.rs | 18 +++++++++--------- ostd/src/sync/rcu/non_null/mod.rs | 8 ++++---- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/ostd/src/sync/rcu/mod.rs b/ostd/src/sync/rcu/mod.rs index 8a86db13..53e81691 100644 --- a/ostd/src/sync/rcu/mod.rs +++ b/ostd/src/sync/rcu/mod.rs @@ -121,7 +121,7 @@ unsafe impl Send for RcuInner

where P: Send {} // of `P` created on another thread. unsafe impl Sync for RcuInner

where P: Send + Sync {} -impl RcuInner

{ +impl RcuInner

{ const fn new_none() -> Self { Self { ptr: AtomicPtr::new(core::ptr::null_mut()), @@ -200,7 +200,7 @@ struct RcuReadGuardInner<'a, P: NonNullPtr> { _inner_guard: DisabledPreemptGuard, } -impl RcuReadGuardInner<'_, P> { +impl RcuReadGuardInner<'_, P> { fn get(&self) -> Option> { // SAFETY: The guard ensures that `P` will not be dropped. Thus, `P` // outlives the lifetime of `&self`. Additionally, during this period, @@ -240,7 +240,7 @@ impl RcuReadGuardInner<'_, P> { } } -impl Rcu

{ +impl Rcu

{ /// Creates a new RCU primitive with the given pointer. pub fn new(pointer: P) -> Self { Self(RcuInner::new(pointer)) @@ -281,7 +281,7 @@ impl Rcu

{ } } -impl RcuOption

{ +impl RcuOption

{ /// Creates a new RCU primitive with the given pointer. pub fn new(pointer: Option

) -> Self { if let Some(pointer) = pointer { @@ -336,7 +336,7 @@ impl RcuOption

{ } } -impl RcuReadGuard<'_, P> { +impl RcuReadGuard<'_, P> { /// Gets the reference of the protected data. pub fn get(&self) -> P::Ref<'_> { self.0.get().unwrap() @@ -362,7 +362,7 @@ impl RcuReadGuard<'_, P> { } } -impl RcuOptionReadGuard<'_, P> { +impl RcuOptionReadGuard<'_, P> { /// Gets the reference of the protected data. /// /// If the RCU primitive protects nothing, this function returns `None`. @@ -398,12 +398,12 @@ impl RcuOptionReadGuard<'_, P> { /// /// The pointer must be previously returned by `into_raw` and the pointer /// must be only be dropped once. -unsafe fn delay_drop(pointer: NonNull<

::Target>) { - struct ForceSend(NonNull<

::Target>); +unsafe fn delay_drop(pointer: NonNull<

::Target>) { + struct ForceSend(NonNull<

::Target>); // SAFETY: Sending a raw pointer to another task is safe as long as // the pointer access in another task is safe (guaranteed by the trait // bound `P: Send`). - unsafe impl Send for ForceSend

{} + unsafe impl Send for ForceSend

{} let pointer: ForceSend

= ForceSend(pointer); diff --git a/ostd/src/sync/rcu/non_null/mod.rs b/ostd/src/sync/rcu/non_null/mod.rs index 7ed0d773..a0b1b800 100644 --- a/ostd/src/sync/rcu/non_null/mod.rs +++ b/ostd/src/sync/rcu/non_null/mod.rs @@ -23,7 +23,7 @@ use crate::prelude::*; /// raw pointers. /// /// [`Rcu`]: super::Rcu -pub unsafe trait NonNullPtr: Send + 'static { +pub unsafe trait NonNullPtr: 'static { /// The target type that this pointer refers to. // TODO: Support `Target: ?Sized`. type Target; @@ -102,7 +102,7 @@ impl<'a, T> BoxRef<'a, T> { } } -unsafe impl NonNullPtr for Box { +unsafe impl NonNullPtr for Box { type Target = T; type Ref<'a> @@ -164,7 +164,7 @@ impl<'a, T> ArcRef<'a, T> { } } -unsafe impl NonNullPtr for Arc { +unsafe impl NonNullPtr for Arc { type Target = T; type Ref<'a> @@ -218,7 +218,7 @@ impl Deref for WeakRef<'_, T> { } } -unsafe impl NonNullPtr for Weak { +unsafe impl NonNullPtr for Weak { type Target = T; type Ref<'a>