Re: [PATCH 3/3] rust: block: convert `block::mq` to use `Refcount`

From: Andreas Hindborg
Date: Fri Oct 04 2024 - 16:40:07 EST


"Gary Guo" <gary@xxxxxxxxxxx> writes:

> On Fri, 04 Oct 2024 20:34:01 +0200
> Andreas Hindborg <a.hindborg@xxxxxxxxxx> wrote:
>
>> Hi Gary,
>>
>> "Gary Guo" <gary@xxxxxxxxxxx> writes:
>>
>> [...]
>>
>> > // SAFETY: All instances of `Request<T>` are reference counted. This
>> > // implementation of `AlwaysRefCounted` ensure that increments to the ref count
>> > // keeps the object alive in memory at least until a matching reference count
>> > // decrement is executed.
>> > unsafe impl<T: Operations> AlwaysRefCounted for Request<T> {
>> > fn inc_ref(&self) {
>> > - let refcount = &self.wrapper_ref().refcount();
>> > -
>> > - #[cfg_attr(not(CONFIG_DEBUG_MISC), allow(unused_variables))]
>> > - let updated = atomic_relaxed_op_unless(refcount, |x| x + 1, 0);
>> > -
>> > - #[cfg(CONFIG_DEBUG_MISC)]
>> > - if !updated {
>> > - panic!("Request refcount zero on clone")
>> > - }
>> > + self.wrapper_ref().refcount().inc();
>>
>> What happened to the debug code?
>>
>>
>> BR Andreas
>>
>
> `refcount_inc` will WARN and saturate the refcount when trying to
> increment from zero. This is true regardless of config.
>
> I've already captured this in `Refcount::inc` documentation.

I did not know. Thanks!

BR Andreas