提交 3b1d8169 编写于 作者: P Paolo Bonzini 提交者: Peter Maydell

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: NAlex Bennée <alex.bennee@linaro.org>
Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
Tested-by: NGreg Kurz <groug@kaod.org>
Message-id: 20170227111726.9237-1-pbonzini@redhat.com
Signed-off-by: NPeter Maydell <peter.maydell@linaro.org>
上级 d992f2f1
......@@ -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);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册