qemu-devel
[Top][All Lists]
Advanced

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

Re: [Qemu-devel] [PATCH 2/5] lock-guard: add scoped lock implementation


From: Eric Blake
Subject: Re: [Qemu-devel] [PATCH 2/5] lock-guard: add scoped lock implementation
Date: Mon, 11 Dec 2017 07:51:43 -0600
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0

On 12/11/2017 04:16 AM, Stefan Hajnoczi wrote:

>>> I don't understand the need for the qemu_lock_guard_is_taken(&name)
>>> condition, why not do the following?
>>>
>>>   for (QEMU_LOCK_GUARD(type, name, lock);
>>>        ;
>>>        qemu_lock_guard_unlock(&name))
>>
>> Because that would be an infinite loop. :)
> 
> Sorry, I mean for (...; false; ...).  Is there any reason to do
> qemu_lock_guard_is_taken(&name)?

You need the loop to execute at least once ;)

But I proposed an alternative that doesn't need is_taken, by:

for (bool name##done = false, QEMU_LOCK_GUARD(type, name, lock);
     ! name##done; name##done = true)

if we still like the form that declares a for-loop scope.

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

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