diff options
author | Emilio G. Cota <cota@braap.org> | 2015-08-23 20:23:36 -0400 |
---|---|---|
committer | Paolo Bonzini <pbonzini@redhat.com> | 2015-09-07 18:12:39 +0200 |
commit | d12f7309483e20d1bae9304f4b812bf53a8e6510 (patch) | |
tree | dcf0514e8f089dd8a0d610688f5e1e2435e8a6a9 | |
parent | 123fdbac9b8f1e394fbe92e8b5359193e94ba5bf (diff) | |
download | qemu-d12f7309483e20d1bae9304f4b812bf53a8e6510.zip qemu-d12f7309483e20d1bae9304f4b812bf53a8e6510.tar.gz qemu-d12f7309483e20d1bae9304f4b812bf53a8e6510.tar.bz2 |
seqlock: read sequence number atomically
With this change we make sure that the compiler will not
optimise the read of the sequence number in any way.
Signed-off-by: Emilio G. Cota <cota@braap.org>
Message-Id: <1440375847-17603-8-git-send-email-cota@braap.org>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
-rw-r--r-- | include/qemu/seqlock.h | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/include/qemu/seqlock.h b/include/qemu/seqlock.h index f1256f5..70b01fd 100644 --- a/include/qemu/seqlock.h +++ b/include/qemu/seqlock.h @@ -55,18 +55,18 @@ static inline void seqlock_write_unlock(QemuSeqLock *sl) static inline unsigned seqlock_read_begin(QemuSeqLock *sl) { /* Always fail if a write is in progress. */ - unsigned ret = sl->sequence & ~1; + unsigned ret = atomic_read(&sl->sequence); /* Read sequence before reading other fields. */ smp_rmb(); - return ret; + return ret & ~1; } static inline int seqlock_read_retry(const QemuSeqLock *sl, unsigned start) { /* Read other fields before reading final sequence. */ smp_rmb(); - return unlikely(sl->sequence != start); + return unlikely(atomic_read(&sl->sequence) != start); } #endif |