diff options
author | Paolo Bonzini <pbonzini@redhat.com> | 2017-02-27 12:17:26 +0100 |
---|---|---|
committer | Stefan Hajnoczi <stefanha@redhat.com> | 2017-02-27 14:00:53 +0000 |
commit | 1ab17f9f5c63c2798d707aeb22588e4fcc17b2cd (patch) | |
tree | 6ae3e0784c3a75bcea37c3d30bce2c2fb8a0b5f1 | |
parent | d045c466d9e62b4321fadf586d024d54ddfd8bd4 (diff) | |
download | qemu-1ab17f9f5c63c2798d707aeb22588e4fcc17b2cd.zip qemu-1ab17f9f5c63c2798d707aeb22588e4fcc17b2cd.tar.gz qemu-1ab17f9f5c63c2798d707aeb22588e4fcc17b2cd.tar.bz2 |
tests-aio-multithread: use atomic_read properly
nodes[id].next is written by other threads. If atomic_read is not used
(matching atomic_set in mcs_mutex_lock!) the compiler can optimize the
whole "if" away!
Reported-by: Alex Bennée <alex.bennee@linaro.org>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Tested-by: Greg Kurz <groug@kaod.org>
Message-id: 20170227111726.9237-1-pbonzini@redhat.com
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
-rw-r--r-- | tests/test-aio-multithread.c | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/tests/test-aio-multithread.c b/tests/test-aio-multithread.c index f11e990..8b0b40e 100644 --- a/tests/test-aio-multithread.c +++ b/tests/test-aio-multithread.c @@ -309,7 +309,7 @@ static void mcs_mutex_lock(void) static void mcs_mutex_unlock(void) { int next; - if (nodes[id].next == -1) { + if (atomic_read(&nodes[id].next) == -1) { if (atomic_read(&mutex_head) == id && atomic_cmpxchg(&mutex_head, id, -1) == id) { /* Last item in the list, exit. */ @@ -323,7 +323,7 @@ static void mcs_mutex_unlock(void) } /* Wake up the next in line. */ - next = nodes[id].next; + next = atomic_read(&nodes[id].next); nodes[next].locked = 0; qemu_futex_wake(&nodes[next].locked, 1); } |