Remove Send trait bound from NonNullPtr

This commit is contained in:
Ruihan Li 2025-04-11 16:25:12 +08:00 committed by Tate, Hongliang Tian
parent de69fd6c31
commit e0bda4677c
2 changed files with 13 additions and 13 deletions

View File

@ -121,7 +121,7 @@ unsafe impl<P: NonNullPtr> Send for RcuInner<P> where P: Send {}
// of `P` created on another thread.
unsafe impl<P: NonNullPtr> Sync for RcuInner<P> where P: Send + Sync {}
impl<P: NonNullPtr> RcuInner<P> {
impl<P: NonNullPtr + Send> RcuInner<P> {
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<P: NonNullPtr> RcuReadGuardInner<'_, P> {
impl<P: NonNullPtr + Send> RcuReadGuardInner<'_, P> {
fn get(&self) -> Option<P::Ref<'_>> {
// 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<P: NonNullPtr> RcuReadGuardInner<'_, P> {
}
}
impl<P: NonNullPtr> Rcu<P> {
impl<P: NonNullPtr + Send> Rcu<P> {
/// Creates a new RCU primitive with the given pointer.
pub fn new(pointer: P) -> Self {
Self(RcuInner::new(pointer))
@ -281,7 +281,7 @@ impl<P: NonNullPtr> Rcu<P> {
}
}
impl<P: NonNullPtr> RcuOption<P> {
impl<P: NonNullPtr + Send> RcuOption<P> {
/// Creates a new RCU primitive with the given pointer.
pub fn new(pointer: Option<P>) -> Self {
if let Some(pointer) = pointer {
@ -336,7 +336,7 @@ impl<P: NonNullPtr> RcuOption<P> {
}
}
impl<P: NonNullPtr> RcuReadGuard<'_, P> {
impl<P: NonNullPtr + Send> RcuReadGuard<'_, P> {
/// Gets the reference of the protected data.
pub fn get(&self) -> P::Ref<'_> {
self.0.get().unwrap()
@ -362,7 +362,7 @@ impl<P: NonNullPtr> RcuReadGuard<'_, P> {
}
}
impl<P: NonNullPtr> RcuOptionReadGuard<'_, P> {
impl<P: NonNullPtr + Send> RcuOptionReadGuard<'_, P> {
/// Gets the reference of the protected data.
///
/// If the RCU primitive protects nothing, this function returns `None`.
@ -398,12 +398,12 @@ impl<P: NonNullPtr> RcuOptionReadGuard<'_, P> {
///
/// The pointer must be previously returned by `into_raw` and the pointer
/// must be only be dropped once.
unsafe fn delay_drop<P: NonNullPtr>(pointer: NonNull<<P as NonNullPtr>::Target>) {
struct ForceSend<P: NonNullPtr>(NonNull<<P as NonNullPtr>::Target>);
unsafe fn delay_drop<P: NonNullPtr + Send>(pointer: NonNull<<P as NonNullPtr>::Target>) {
struct ForceSend<P: NonNullPtr + Send>(NonNull<<P as NonNullPtr>::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<P: NonNullPtr> Send for ForceSend<P> {}
unsafe impl<P: NonNullPtr + Send> Send for ForceSend<P> {}
let pointer: ForceSend<P> = ForceSend(pointer);

View File

@ -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<T: Send + 'static> NonNullPtr for Box<T> {
unsafe impl<T: 'static> NonNullPtr for Box<T> {
type Target = T;
type Ref<'a>
@ -164,7 +164,7 @@ impl<'a, T> ArcRef<'a, T> {
}
}
unsafe impl<T: Send + Sync + 'static> NonNullPtr for Arc<T> {
unsafe impl<T: 'static> NonNullPtr for Arc<T> {
type Target = T;
type Ref<'a>
@ -218,7 +218,7 @@ impl<T> Deref for WeakRef<'_, T> {
}
}
unsafe impl<T: Send + Sync + 'static> NonNullPtr for Weak<T> {
unsafe impl<T: 'static> NonNullPtr for Weak<T> {
type Target = T;
type Ref<'a>