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: Paolo Bonzini
Subject: Re: [PATCH 4/6] coroutine-lock: reimplement CoRwLock to fix downgrade bug
Date: Wed, 17 Mar 2021 18:19:58 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.7.0

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.  So that leaves only the of/or typo, right?

Paolo




reply via email to

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