aboutsummaryrefslogtreecommitdiff
path: root/include/qemu
diff options
context:
space:
mode:
authorPaolo Bonzini <pbonzini@redhat.com>2018-08-14 09:48:29 +0200
committerPaolo Bonzini <pbonzini@redhat.com>2018-08-23 18:46:25 +0200
commit988fcafc730242711ba92f9e62557e37f2b22cc0 (patch)
treecd9b802a1d8243aafeb88a6b01742f1934e11585 /include/qemu
parentc1ff073cd88eddce5a0870791431878b96d08157 (diff)
downloadqemu-988fcafc730242711ba92f9e62557e37f2b22cc0.zip
qemu-988fcafc730242711ba92f9e62557e37f2b22cc0.tar.gz
qemu-988fcafc730242711ba92f9e62557e37f2b22cc0.tar.bz2
seqlock: add QemuLockable support
A shortcut when the seqlock write is protected by a spinlock or any mutex other than the BQL. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'include/qemu')
-rw-r--r--include/qemu/seqlock.h20
1 files changed, 20 insertions, 0 deletions
diff --git a/include/qemu/seqlock.h b/include/qemu/seqlock.h
index c367516..fd408b7 100644
--- a/include/qemu/seqlock.h
+++ b/include/qemu/seqlock.h
@@ -16,6 +16,7 @@
#include "qemu/atomic.h"
#include "qemu/thread.h"
+#include "qemu/lockable.h"
typedef struct QemuSeqLock QemuSeqLock;
@@ -45,6 +46,25 @@ static inline void seqlock_write_end(QemuSeqLock *sl)
atomic_set(&sl->sequence, sl->sequence + 1);
}
+/* Lock out other writers and update the count. */
+static inline void seqlock_write_lock_impl(QemuSeqLock *sl, QemuLockable *lock)
+{
+ qemu_lockable_lock(lock);
+ seqlock_write_begin(sl);
+}
+#define seqlock_write_lock(sl, lock) \
+ seqlock_write_lock_impl(sl, QEMU_MAKE_LOCKABLE(lock))
+
+/* Lock out other writers and update the count. */
+static inline void seqlock_write_unlock_impl(QemuSeqLock *sl, QemuLockable *lock)
+{
+ qemu_lockable_unlock(lock);
+ seqlock_write_begin(sl);
+}
+#define seqlock_write_unlock(sl, lock) \
+ seqlock_write_unlock_impl(sl, QEMU_MAKE_LOCKABLE(lock))
+
+
static inline unsigned seqlock_read_begin(const QemuSeqLock *sl)
{
/* Always fail if a write is in progress. */