mirror of
https://github.com/mborgerson/xemu.git
synced 2025-12-01 16:10:01 +00:00
lockable: add QemuLockable
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 <pbonzini@redhat.com> Message-Id: <20180203153935.8056-3-pbonzini@redhat.com> Reviewed-by: Richard Henderson <richard.henderson@linaro.org> Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> Reviewed-by: Fam Zheng <famz@redhat.com> Signed-off-by: Fam Zheng <famz@redhat.com>
This commit is contained in:
@ -121,7 +121,7 @@ bool qemu_coroutine_entered(Coroutine *co);
|
||||
* Provides a mutex that can be used to synchronise coroutines
|
||||
*/
|
||||
struct CoWaitRecord;
|
||||
typedef struct CoMutex {
|
||||
struct CoMutex {
|
||||
/* Count of pending lockers; 0 for a free mutex, 1 for an
|
||||
* uncontended mutex.
|
||||
*/
|
||||
@ -142,7 +142,7 @@ typedef struct CoMutex {
|
||||
unsigned handoff, sequence;
|
||||
|
||||
Coroutine *holder;
|
||||
} CoMutex;
|
||||
};
|
||||
|
||||
/**
|
||||
* Initialises a CoMutex. This must be called before any other operation is used
|
||||
|
||||
Reference in New Issue
Block a user