Re: [RFC 2/5] rust: sync: Arc: Introduces ArcInner::count()

From: Wedson Almeida Filho
Date: Fri Feb 03 2023 - 14:23:53 EST


On Fri, 3 Feb 2023 at 16:17, Josh Stone <jistone@xxxxxxxxxx> wrote:
>
> On 2/2/23 11:38 PM, Greg KH wrote:
> > How? Because you have an implicit reference on it already? If so, then
> > why does reading from it matter at all, as if you have a reference, you
> > know it isn't 0, and that's all that you can really care about. You
> > don't care about any number other than 0 for a reference count, as by
> > definition, that's what a reference count does :)
>
> There is an additional ability for 1, mentioned up thread -- if you have
> &mut Arc<T>, and the inner count is 1, then you *know* there aren't any
> other Arc<T> handles anywhere else. Then it is safe to return an
> exclusive &mut T, like the upstream Arc::get_mut and Arc::make_mut. This
> can also be used for owned Arc<T> like the upstream Arc::try_unwrap.

The `Arc<T>` in the kernel is pinned so we can't return an `&mut T`,
though a `Pin<&mut T>` would be ok.