Lines Matching defs:ARef

10 //! The smart pointer [`ARef<T>`] acts similarly to [`Arc<T>`] in that it holds a refcount on the
14 //! To make use of [`ARef<MyType>`], `MyType` needs to implement [`AlwaysRefCounted`]. It is a trait
26 /// [`ARef<T>`].
60 /// The object's reference count is automatically decremented when an instance of [`ARef`] is
62 /// [`ARef::clone`].
66 /// The pointer stored in `ptr` is non-null and valid for the lifetime of the [`ARef`] instance. In
67 /// particular, the [`ARef`] instance owns an increment on the underlying object's reference count.
68 pub struct ARef<T: AlwaysRefCounted> {
73 // SAFETY: It is safe to send `ARef<T>` to another thread when the underlying `T` is `Sync` because
75 // `T` to be `Send` because any thread that has an `ARef<T>` may ultimately access `T` using a
77 unsafe impl<T: AlwaysRefCounted + Sync + Send> Send for ARef<T> {}
79 // SAFETY: It is safe to send `&ARef<T>` to another thread when the underlying `T` is `Sync`
81 // it needs `T` to be `Send` because any thread that has a `&ARef<T>` may clone it and get an
82 // `ARef<T>` on that thread, so the thread may ultimately access `T` using a mutable reference, for
84 unsafe impl<T: AlwaysRefCounted + Sync + Send> Sync for ARef<T> {}
86 impl<T: AlwaysRefCounted> ARef<T> {
87 /// Creates a new instance of [`ARef`].
96 /// created [`ARef`].
106 /// Consumes the `ARef`, returning a raw pointer.
109 /// responsible for the refcount previously managed by the `ARef`.
115 /// use kernel::sync::aref::{ARef, AlwaysRefCounted};
128 /// let data_ref: ARef<Empty> = unsafe { ARef::from_raw(ptr) };
129 /// let raw_ptr: NonNull<Empty> = ARef::into_raw(data_ref);
138 impl<T: AlwaysRefCounted> Clone for ARef<T> {
146 impl<T: AlwaysRefCounted> Deref for ARef<T> {
155 impl<T: AlwaysRefCounted> From<&T> for ARef<T> {
163 impl<T: AlwaysRefCounted> Drop for ARef<T> {
165 // SAFETY: The type invariants guarantee that the `ARef` owns the reference we're about to