From bf8c3c1d7b191e3e6925e704efaa9da42f6c7e53 Mon Sep 17 00:00:00 2001 From: ad Date: Mon, 12 Mar 2007 22:34:08 +0000 Subject: [PATCH] mutex_vector_enter: put a read memory barrier between the final check that (1) the holder is no longer running and (2) the waiters bit is set. Needed to ensure that the operations happen in the correct order. --- sys/kern/kern_mutex.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/sys/kern/kern_mutex.c b/sys/kern/kern_mutex.c index 8c0642301f32..78368ba9d1e4 100644 --- a/sys/kern/kern_mutex.c +++ b/sys/kern/kern_mutex.c @@ -1,4 +1,4 @@ -/* $NetBSD: kern_mutex.c,v 1.12 2007/03/12 02:19:14 matt Exp $ */ +/* $NetBSD: kern_mutex.c,v 1.13 2007/03/12 22:34:08 ad Exp $ */ /*- * Copyright (c) 2002, 2006, 2007 The NetBSD Foundation, Inc. @@ -49,7 +49,7 @@ #define __MUTEX_PRIVATE #include -__KERNEL_RCSID(0, "$NetBSD: kern_mutex.c,v 1.12 2007/03/12 02:19:14 matt Exp $"); +__KERNEL_RCSID(0, "$NetBSD: kern_mutex.c,v 1.13 2007/03/12 22:34:08 ad Exp $"); #include #include @@ -646,8 +646,8 @@ mutex_vector_enter(kmutex_t *mtx) * If the waiters bit is not set it's unsafe to go asleep, * as we might never be awoken. */ - mb_read(); - if (mutex_onproc(owner, &ci) || !MUTEX_HAS_WAITERS(mtx)) { + if ((mb_read(), mutex_onproc(owner, &ci)) || + (mb_read(), !MUTEX_HAS_WAITERS(mtx))) { turnstile_exit(mtx); continue; }