mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-09 21:36:48 +00:00
Remove Send
trait bound from NonNullPtr
This commit is contained in:
parent
de69fd6c31
commit
e0bda4677c
@ -121,7 +121,7 @@ unsafe impl<P: NonNullPtr> Send for RcuInner<P> where P: Send {}
|
|||||||
// of `P` created on another thread.
|
// of `P` created on another thread.
|
||||||
unsafe impl<P: NonNullPtr> Sync for RcuInner<P> where P: Send + Sync {}
|
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 {
|
const fn new_none() -> Self {
|
||||||
Self {
|
Self {
|
||||||
ptr: AtomicPtr::new(core::ptr::null_mut()),
|
ptr: AtomicPtr::new(core::ptr::null_mut()),
|
||||||
@ -200,7 +200,7 @@ struct RcuReadGuardInner<'a, P: NonNullPtr> {
|
|||||||
_inner_guard: DisabledPreemptGuard,
|
_inner_guard: DisabledPreemptGuard,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<P: NonNullPtr> RcuReadGuardInner<'_, P> {
|
impl<P: NonNullPtr + Send> RcuReadGuardInner<'_, P> {
|
||||||
fn get(&self) -> Option<P::Ref<'_>> {
|
fn get(&self) -> Option<P::Ref<'_>> {
|
||||||
// SAFETY: The guard ensures that `P` will not be dropped. Thus, `P`
|
// SAFETY: The guard ensures that `P` will not be dropped. Thus, `P`
|
||||||
// outlives the lifetime of `&self`. Additionally, during this period,
|
// 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.
|
/// Creates a new RCU primitive with the given pointer.
|
||||||
pub fn new(pointer: P) -> Self {
|
pub fn new(pointer: P) -> Self {
|
||||||
Self(RcuInner::new(pointer))
|
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.
|
/// Creates a new RCU primitive with the given pointer.
|
||||||
pub fn new(pointer: Option<P>) -> Self {
|
pub fn new(pointer: Option<P>) -> Self {
|
||||||
if let Some(pointer) = pointer {
|
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.
|
/// Gets the reference of the protected data.
|
||||||
pub fn get(&self) -> P::Ref<'_> {
|
pub fn get(&self) -> P::Ref<'_> {
|
||||||
self.0.get().unwrap()
|
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.
|
/// Gets the reference of the protected data.
|
||||||
///
|
///
|
||||||
/// If the RCU primitive protects nothing, this function returns `None`.
|
/// 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
|
/// The pointer must be previously returned by `into_raw` and the pointer
|
||||||
/// must be only be dropped once.
|
/// must be only be dropped once.
|
||||||
unsafe fn delay_drop<P: NonNullPtr>(pointer: NonNull<<P as NonNullPtr>::Target>) {
|
unsafe fn delay_drop<P: NonNullPtr + Send>(pointer: NonNull<<P as NonNullPtr>::Target>) {
|
||||||
struct ForceSend<P: NonNullPtr>(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
|
// 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
|
// the pointer access in another task is safe (guaranteed by the trait
|
||||||
// bound `P: Send`).
|
// 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);
|
let pointer: ForceSend<P> = ForceSend(pointer);
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@ use crate::prelude::*;
|
|||||||
/// raw pointers.
|
/// raw pointers.
|
||||||
///
|
///
|
||||||
/// [`Rcu`]: super::Rcu
|
/// [`Rcu`]: super::Rcu
|
||||||
pub unsafe trait NonNullPtr: Send + 'static {
|
pub unsafe trait NonNullPtr: 'static {
|
||||||
/// The target type that this pointer refers to.
|
/// The target type that this pointer refers to.
|
||||||
// TODO: Support `Target: ?Sized`.
|
// TODO: Support `Target: ?Sized`.
|
||||||
type Target;
|
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 Target = T;
|
||||||
|
|
||||||
type Ref<'a>
|
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 Target = T;
|
||||||
|
|
||||||
type Ref<'a>
|
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 Target = T;
|
||||||
|
|
||||||
type Ref<'a>
|
type Ref<'a>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user