qemu-block
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH 4/6] coroutine-lock: reimplement CoRwLock to fix downgrade bu


From: David Edmondson
Subject: Re: [PATCH 4/6] coroutine-lock: reimplement CoRwLock to fix downgrade bug
Date: Wed, 17 Mar 2021 17:47:07 +0000

On Wednesday, 2021-03-17 at 18:19:58 +01, Paolo Bonzini wrote:

> On 17/03/21 16:17, David Edmondson wrote:
>>> +    if (tkt) {
>>> +        if (tkt->read) {
>>> +            if (lock->owners >= 0) {
>>> +                lock->owners++;
>>> +                co = tkt->co;
>>> +            }
>>> +        } else {
>>> +            if (lock->owners == 0) {
>>> +                lock->owners = -1;
>>> +                co = tkt->co;
>>> +            }
>>> +        }
>>> +    }
>>> +
>>> +    if (co) {
>>> +        QSIMPLEQ_REMOVE_HEAD(&lock->tickets, next);
>>> +        qemu_co_mutex_unlock(&lock->mutex);
>>> +        aio_co_wake(co);
>>> +    } else {
>>> +        qemu_co_mutex_unlock(&lock->mutex);
>>> +    }
>> 
>> This block could be pushed up into the earlier block, but I imagine that
>> the compiler will do it for you.
>
> I guess I could do
>
>      if (!tkt || (tkt->read ? lock->owners < 0 : lock->owners != 0)) {
>          qemu_co_mutex_unlock(&lock->mutex);
>          return;
>      }
>      if (tkt->read) {
>          lock->owners++;
>      } else {
>          lock->owners = -1;
>      }
>
>      co = tkt->co;
>      QSIMPLEQ_REMOVE_HEAD(&lock->tickets, next);
>      qemu_co_mutex_unlock(&lock->mutex);
>      aio_co_wake(co);
>
> but I find it less readable.

Agreed.

> So that leaves only the of/or typo, right?

Yes.

dme.
-- 
In heaven there is no beer, that's why we drink it here.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]