summaryrefslogtreecommitdiffstats
path: root/include/qemu/seqlock.h
Commit message (Collapse)AuthorAgeFilesLines
* qemu/atomic.h: rename atomic_ to qatomic_Stefan Hajnoczi2020-09-231-4/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | clang's C11 atomic_fetch_*() functions only take a C11 atomic type pointer argument. QEMU uses direct types (int, etc) and this causes a compiler error when a QEMU code calls these functions in a source file that also included <stdatomic.h> via a system header file: $ CC=clang CXX=clang++ ./configure ... && make ../util/async.c:79:17: error: address argument to atomic operation must be a pointer to _Atomic type ('unsigned int *' invalid) Avoid using atomic_*() names in QEMU's atomic.h since that namespace is used by <stdatomic.h>. Prefix QEMU's APIs with 'q' so that atomic.h and <stdatomic.h> can co-exist. I checked /usr/include on my machine and searched GitHub for existing "qatomic_" users but there seem to be none. This patch was generated using: $ git grep -h -o '\<atomic\(64\)\?_[a-z0-9_]\+' include/qemu/atomic.h | \ sort -u >/tmp/changed_identifiers $ for identifier in $(</tmp/changed_identifiers); do sed -i "s%\<$identifier\>%q$identifier%g" \ $(git grep -I -l "\<$identifier\>") done I manually fixed line-wrap issues and misaligned rST tables. Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> Acked-by: Paolo Bonzini <pbonzini@redhat.com> Message-Id: <20200923105646.47864-1-stefanha@redhat.com>
* seqlock: fix seqlock_write_unlock_impl functionLuc Michel2020-02-121-2/+2
| | | | | | | | | | | | | | The seqlock write unlock function was incorrectly calling seqlock_write_begin() instead of seqlock_write_end(), and was releasing the lock before incrementing the sequence. This could lead to a race condition and a corrupted sequence number becoming odd even though the lock is not held. Signed-off-by: Luc Michel <luc.michel@greensocs.com> Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> Message-Id: <20200129144948.2161551-1-luc.michel@greensocs.com> Fixes: 988fcafc73 ("seqlock: add QemuLockable support", 2018-08-23) Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* seqlock: add QemuLockable supportPaolo Bonzini2018-08-231-0/+20
| | | | | | | 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>
* seqlock: constify seqlock_read_beginEmilio G. Cota2018-08-231-1/+1
| | | | | Signed-off-by: Emilio G. Cota <cota@braap.org> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* seqlock: use atomic writes for the sequencePaolo Bonzini2016-10-041-2/+2
| | | | | | | | | | | | There is a data race if the sequence is written concurrently to the read. In C11 this has undefined behavior. Use atomic_set; the read side is already using atomic_read. Reported-by: Alex Bennée <alex.bennee@linaro.org> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Alex Bennée <alex.bennee@linaro.org> Message-Id: <20160930213106.20186-6-alex.bennee@linaro.org> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* Clean up decorations and whitespace around header guardsMarkus Armbruster2016-07-121-1/+2
| | | | | | | Cleaned up with scripts/clean-header-guards.pl. Signed-off-by: Markus Armbruster <armbru@redhat.com> Reviewed-by: Richard Henderson <rth@twiddle.net>
* Use #include "..." for our own headers, <...> for othersMarkus Armbruster2016-07-121-2/+2
| | | | | | | | | | | | Tracked down with an ugly, brittle and probably buggy Perl script. Also move includes converted to <...> up so they get included before ours where that's obviously okay. Signed-off-by: Markus Armbruster <armbru@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com> Tested-by: Eric Blake <eblake@redhat.com> Reviewed-by: Richard Henderson <rth@twiddle.net>
* seqlock: rename write_lock/unlock to write_begin/endEmilio G. Cota2016-06-121-2/+2
| | | | | | | | | | | | It is a more appropriate name, now that the mutex embedded in the seqlock is gone. Reviewed-by: Sergey Fedorov <sergey.fedorov@linaro.org> Reviewed-by: Alex Bennée <alex.bennee@linaro.org> Reviewed-by: Richard Henderson <rth@twiddle.net> Signed-off-by: Emilio G. Cota <cota@braap.org> Message-Id: <1465412133-3029-4-git-send-email-cota@braap.org> Signed-off-by: Richard Henderson <rth@twiddle.net>
* seqlock: remove optional mutexEmilio G. Cota2016-06-121-9/+1Star
| | | | | | | | | | | | This option is unused; besides, it bloats the struct when not needed. Let's just let writers define their own locks elsewhere. Reviewed-by: Sergey Fedorov <sergey.fedorov@linaro.org> Reviewed-by: Alex Bennée <alex.bennee@linaro.org> Reviewed-by: Richard Henderson <rth@twiddle.net> Signed-off-by: Emilio G. Cota <cota@braap.org> Message-Id: <1465412133-3029-3-git-send-email-cota@braap.org> Signed-off-by: Richard Henderson <rth@twiddle.net>
* seqlock: read sequence number atomicallyEmilio G. Cota2015-09-071-3/+3
| | | | | | | | | 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>
* seqlock: add missing 'inline' to seqlock_read_retryEmilio G. Cota2015-09-071-1/+1
| | | | | | | Signed-off-by: Emilio G. Cota <cota@braap.org> Message-Id: <1440375847-17603-7-git-send-email-cota@braap.org> Reviewed-by: Alex Bennée <alex.bennee@linaro.org> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* seqlock: introduce read-write seqlockPaolo Bonzini2013-10-171-0/+72
Seqlock implementation for QEMU. Usage idiom reader: do { start = seqlock_read_begin(&sl); ... } while (seqlock_read_retry(&sl, start)); writer: seqlock_write_lock(&sl); ... seqlock_write_unlock(&sl); initialization: seqlock_init(QemuSeqLock *sl, QemuMutex *mutex) mutex could be NULL if the caller will provide its own protection for concurrent write sides (typically using the BQL). Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>