[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: |
Stefan Hajnoczi |
Subject: |
Re: [Qemu-devel] [PATCH 2/5] lock-guard: add scoped lock implementation |
Date: |
Tue, 12 Dec 2017 09:16:31 +0000 |
User-agent: |
Mutt/1.9.1 (2017-09-22) |
On Mon, Dec 11, 2017 at 07:51:43AM -0600, Eric Blake wrote:
> 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.
Okay guys, for loops are hard. I give up programming.
Stefan
signature.asc
Description: PGP signature
[Qemu-devel] [PATCH 3/5] qemu-timer: convert to use lock guards, Paolo Bonzini, 2017/12/08
[Qemu-devel] [PATCH 4/5] qht: convert to use lock guards, Paolo Bonzini, 2017/12/08
[Qemu-devel] [PATCH 5/5] thread-pool: convert to use lock guards, Paolo Bonzini, 2017/12/08