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_expr and > __builtin_types_compatible_p, which are already used by > include/qemu/atomic.h. > > QemuLockable can be used to implement lock guards, or to pass around > a lock in such a way that a function can release it and re-acquire it. > The next patch will do this for CoQueue. > > Signed-off-by: Paolo Bonzini <pbonz...@redhat.com> > ---
> + > +static inline __attribute__((__always_inline__)) QemuLockable * > +qemu_make_lockable(void *x, QemuLockable *lockable) > +{ > + /* We cannot test this in a macro, otherwise we get * compiler Spurious '*' ? > + * warnings like "the address of 'm' will always evaluate as 'true'". > + */ > + return x ? lockable : NULL; > +} > + -- Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org
signature.asc
Description: OpenPGP digital signature