Re: [Qemu-devel] [PATCH 2/5] lockable: add QemuLockable

2018-02-05 Thread Paolo Bonzini
On 03/02/2018 21:44, Richard Henderson wrote: > On 02/03/2018 07:39 AM, Paolo Bonzini wrote: >> +/* This function gives an error if an invalid, non-NULL pointer type is >> passed >> + * to QEMU_MAKE_LOCKABLE. For optimized builds, we can rely on dead-code >> elimination >> + * from the compiler,

Re: [Qemu-devel] [PATCH 2/5] lockable: add QemuLockable

2018-02-03 Thread Richard Henderson
On 02/03/2018 07:39 AM, Paolo Bonzini wrote: > +/* This function gives an error if an invalid, non-NULL pointer type is > passed > + * to QEMU_MAKE_LOCKABLE. For optimized builds, we can rely on dead-code > elimination > + * from the compiler, and give the errors already at link time. > + */ > +

[Qemu-devel] [PATCH 2/5] lockable: add QemuLockable

2018-02-03 Thread Paolo Bonzini
QemuLockable is a polymorphic lock type that takes an object and knows which function to use for locking and unlocking. The implementation could use C11 _Generic, but since the support is not very widespread I am instead using __builtin_choose_expr and __builtin_types_compatible_p, which are alrea

[Qemu-devel] [PATCH 2/5] lockable: add QemuLockable

2018-02-01 Thread Paolo Bonzini
QemuLockable is a polymorphic lock type that takes an object and knows which function to use for locking and unlocking. The implementation could use C11 _Generic, but since the support is not very widespread I am instead using __builtin_choose_expr and __builtin_types_compatible_p, which are alrea

Re: [Qemu-devel] [PATCH 2/5] lockable: add QemuLockable

2018-01-29 Thread Paolo Bonzini
On 29/01/2018 12:42, Stefan Hajnoczi wrote: > On Thu, Jan 25, 2018 at 06:59:46PM +0100, Paolo Bonzini wrote: >> +struct QemuLockable { >> +void *object; >> +QemuLockUnlockFunc *lock; >> +QemuLockUnlockFunc *unlock; >> +}; > ... >> +/* In C, compound literals have the lifetime of an auto

Re: [Qemu-devel] [PATCH 2/5] lockable: add QemuLockable

2018-01-29 Thread Stefan Hajnoczi
On Thu, Jan 25, 2018 at 06:59:46PM +0100, Paolo Bonzini wrote: > +struct QemuLockable { > +void *object; > +QemuLockUnlockFunc *lock; > +QemuLockUnlockFunc *unlock; > +}; ... > +/* In C, compound literals have the lifetime of an automatic variable. > + * In C++ it would be different, bu

Re: [Qemu-devel] [PATCH 2/5] lockable: add QemuLockable

2018-01-26 Thread Fam Zheng
On Fri, Jan 26, 2018 at 1:59 AM, Paolo Bonzini wrote: > QemuLockable is a polymorphic lock type that takes an object and > knows which function to use for locking and unlocking. The > implementation could use C11 _Generic, but since the support is > not very widespread I am instead using __builti

Re: [Qemu-devel] [PATCH 2/5] lockable: add QemuLockable

2018-01-25 Thread Fam Zheng
On Fri, Jan 26, 2018 at 1:59 AM, Paolo Bonzini wrote: > diff --git a/include/qemu/lockable.h b/include/qemu/lockable.h > new file mode 100644 > index 00..f527d0ddb2 > --- /dev/null > +++ b/include/qemu/lockable.h > @@ -0,0 +1,88 @@ > +/* > + * Polymorphic locking functions (aka poor man te

Re: [Qemu-devel] [PATCH 2/5] lockable: add QemuLockable

2018-01-25 Thread Eric Blake
On 01/25/2018 11:59 AM, Paolo Bonzini wrote: > QemuLockable is a polymorphic lock type that takes an object and > knows which function to use for locking and unlocking. The > implementation could use C11 _Generic, but since the support is > not very widespread I am instead using __builtin_choose_e

[Qemu-devel] [PATCH 2/5] lockable: add QemuLockable

2018-01-25 Thread Paolo Bonzini
QemuLockable is a polymorphic lock type that takes an object and knows which function to use for locking and unlocking. The implementation could use C11 _Generic, but since the support is not very widespread I am instead using __builtin_choose_expr and __builtin_types_compatible_p, which are alrea