On Fri, Dec 08, 2017 at 06:56:12PM +0100, Paolo Bonzini wrote: > On 08/12/2017 16:30, Stefan Hajnoczi wrote: > > On Fri, Dec 08, 2017 at 11:55:50AM +0100, Paolo Bonzini wrote: > > > > The implementation is somewhat complex. Please structure the header > > file so the public interfaces are clear and documented. Move the > > implementation out of the way and mark it private. That will make it > > easier for someone to figure out "how do I use lock-guard.h". > > Right, unfortunately you pretty much have to place it in the header to > guarantee that everything is inlined.
Yes, that's fine. I think the important part is to put public interfaces next to each other and document them. > >> +#define QEMU_WITH_LOCK(type, name, lock) > >> \ > >> + for (QEMU_LOCK_GUARD(type, name, lock); > >> \ > >> + qemu_lock_guard_is_taken(&name); > >> \ > >> + qemu_lock_guard_unlock(&name)) > > > > 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)?
signature.asc
Description: PGP signature