Lines Matching full:arc

10 //! It is different from the standard library's [`Arc`] in a few ways:
16 //! [`Arc`]: https://doc.rust-lang.org/std/sync/struct.Arc.html
41 /// The reference count is incremented when new instances of [`Arc`] are created, and decremented
46 /// The reference count on an instance of [`Arc`] is always non-zero.
47 /// The object pointed to by [`Arc`] is always pinned.
52 /// use kernel::sync::Arc;
60 /// let obj = Arc::try_new(Example { a: 10, b: 20 })?;
79 /// Using `Arc<T>` as the type of `self`:
82 /// use kernel::sync::Arc;
90 /// fn take_over(self: Arc<Self>) {
94 /// fn use_reference(self: &Arc<Self>) {
99 /// let obj = Arc::try_new(Example { a: 10, b: 20 })?;
105 /// Coercion from `Arc<Example>` to `Arc<dyn MyTrait>`:
108 /// use kernel::sync::{Arc, ArcBorrow};
111 /// // Trait has a function whose `self` type is `Arc<Self>`.
112 /// fn example1(self: Arc<Self>) {}
121 /// // `obj` has type `Arc<Example>`.
122 /// let obj: Arc<Example> = Arc::try_new(Example)?;
124 /// // `coerced` has type `Arc<dyn MyTrait>`.
125 /// let coerced: Arc<dyn MyTrait> = obj;
128 pub struct Arc<T: ?Sized> { struct
140 // This is to allow [`Arc`] (and variants) to be used as the type of `self`.
141 impl<T: ?Sized> core::ops::Receiver for Arc<T> {} implementation
143 // This is to allow coercion from `Arc<T>` to `Arc<U>` if `T` can be converted to the
145 impl<T: ?Sized + Unsize<U>, U: ?Sized> core::ops::CoerceUnsized<Arc<U>> for Arc<T> {} implementation
147 // This is to allow `Arc<U>` to be dispatched on when `Arc<T>` can be coerced into `Arc<U>`.
148 impl<T: ?Sized + Unsize<U>, U: ?Sized> core::ops::DispatchFromDyn<Arc<U>> for Arc<T> {} implementation
150 // SAFETY: It is safe to send `Arc<T>` to another thread when the underlying `T` is `Sync` because
152 // `T` to be `Send` because any thread that has an `Arc<T>` may ultimately access `T` using a
154 unsafe impl<T: ?Sized + Sync + Send> Send for Arc<T> {} implementation
156 // SAFETY: It is safe to send `&Arc<T>` to another thread when the underlying `T` is `Sync`
158 // it needs `T` to be `Send` because any thread that has a `&Arc<T>` may clone it and get an
159 // `Arc<T>` on that thread, so the thread may ultimately access `T` using a mutable reference when
161 unsafe impl<T: ?Sized + Sync + Send> Sync for Arc<T> {} implementation
163 impl<T> Arc<T> { implementation
176 // `Arc` object. in try_new()
193 /// This is equivalent to [`Arc<T>::pin_init`], since an [`Arc`] is always pinned.
203 impl<T: ?Sized> Arc<T> { implementation
204 /// Constructs a new [`Arc`] from an existing [`ArcInner`].
209 /// count, one of which will be owned by the new [`Arc`] instance.
212 Arc { in from_inner()
218 /// Returns an [`ArcBorrow`] from the given [`Arc`].
221 /// receiver), but we have an [`Arc`] instead. Getting an [`ArcBorrow`] is free when optimised.
230 /// Compare whether two [`Arc`] pointers reference the same underlying object.
236 impl<T: 'static> ForeignOwnable for Arc<T> { implementation
245 // a previous call to `Arc::into_foreign`. in borrow()
255 // a previous call to `Arc::into_foreign`, which guarantees that `ptr` is valid and in from_foreign()
261 impl<T: ?Sized> Deref for Arc<T> { implementation
271 impl<T: ?Sized> AsRef<T> for Arc<T> { implementation
277 impl<T: ?Sized> Clone for Arc<T> { implementation
284 // SAFETY: We just incremented the refcount. This increment is now owned by the new `Arc`. in clone()
289 impl<T: ?Sized> Drop for Arc<T> { implementation
297 // INVARIANT: If the refcount reaches zero, there are no other instances of `Arc`, and in drop()
310 impl<T: ?Sized> From<UniqueArc<T>> for Arc<T> { implementation
316 impl<T: ?Sized> From<Pin<UniqueArc<T>>> for Arc<T> { implementation
318 // SAFETY: The type invariants of `Arc` guarantee that the data is pinned. in from()
323 /// A borrowed reference to an [`Arc`] instance.
326 /// to use just `&T`, which we can trivially get from an `Arc<T>` instance.
329 /// over `&Arc<T>` because the latter results in a double-indirection: a pointer (shared reference)
330 /// to a pointer (`Arc<T>`) to the object (`T`). An [`ArcBorrow`] eliminates this double
331 /// indirection while still allowing one to increment the refcount and getting an `Arc<T>` when/if
336 /// There are no mutable references to the underlying [`Arc`], and it remains valid for the
342 /// use kernel::sync::{Arc, ArcBorrow};
346 /// fn do_something(e: ArcBorrow<'_, Example>) -> Arc<Example> {
350 /// let obj = Arc::try_new(Example)?;
361 /// use kernel::sync::{Arc, ArcBorrow};
374 /// let obj = Arc::try_new(Example { a: 10, b: 20 })?;
418 impl<T: ?Sized> From<ArcBorrow<'_, T>> for Arc<T> { implementation
421 // guarantees that `drop` isn't called, so it's ok that the temporary `Arc` doesn't own the in from()
423 ManuallyDrop::new(unsafe { Arc::from_inner(b.inner) }) in from()
441 /// It is mutable and can be converted to an [`Arc`] so that it can be shared.
450 /// `Arc<Test>` object (after which point, it cannot be mutated directly). Note that `x.into()`
454 /// use kernel::sync::{Arc, UniqueArc};
461 /// fn test() -> Result<Arc<Example>> {
473 /// followed by a conversion to `Arc<Example>`. This is particularly useful when allocation happens
477 /// use kernel::sync::{Arc, UniqueArc};
484 /// fn test() -> Result<Arc<Example>> {
493 /// `Arc<Example>`; this is useful in scenarios where one needs a pinned reference during
497 /// use kernel::sync::{Arc, UniqueArc};
504 /// fn test() -> Result<Arc<Example>> {
514 inner: Arc<T>,
522 inner: Arc::try_new(value)?, in try_new()
537 inner: unsafe { Arc::from_inner(Box::leak(inner).into()) }, in try_new_uninit()
559 // SAFETY: The new `Arc` is taking over `ptr` from `self.inner` (which won't be in assume_init()
561 inner: unsafe { Arc::from_inner(inner.cast()) }, in assume_init()
608 // SAFETY: By the `Arc` type invariant, there is necessarily a reference to the object, so in deref_mut()
621 impl<T: fmt::Display + ?Sized> fmt::Display for Arc<T> { implementation
633 impl<T: fmt::Debug + ?Sized> fmt::Debug for Arc<T> { implementation