[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH 2/5] lockable: add QemuLockable
From: |
Eric Blake |
Subject: |
Re: [Qemu-devel] [PATCH 2/5] lockable: add QemuLockable |
Date: |
Thu, 25 Jan 2018 14:13:20 -0600 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.5.2 |
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 <address@hidden>
> ---
> +
> +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
- [Qemu-devel] [PATCH v3 0/5] coroutine-lock: polymorphic CoQueue, Paolo Bonzini, 2018/01/25
- [Qemu-devel] [PATCH 1/5] test-coroutine: add simple CoMutex test, Paolo Bonzini, 2018/01/25
- [Qemu-devel] [PATCH 2/5] lockable: add QemuLockable, Paolo Bonzini, 2018/01/25
- [Qemu-devel] [PATCH 3/5] coroutine-lock: convert CoQueue to use QemuLockable, Paolo Bonzini, 2018/01/25
- [Qemu-devel] [PATCH 4/5] coroutine-lock: make qemu_co_enter_next thread-safe, Paolo Bonzini, 2018/01/25
- [Qemu-devel] [PATCH 5/5] curl: convert to CoQueue, Paolo Bonzini, 2018/01/25