From bcc89a0643aab03595c8abe6985be5adfe940903 Mon Sep 17 00:00:00 2001 From: Miod Vallat Date: Tue, 26 Jan 2010 04:56:05 +0000 Subject: Sprinkle some write buffer flushes, copied from powerpc; prevents lock count from becoming negative under bad timing circumstances. --- sys/arch/sgi/sgi/lock_machdep.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'sys/arch/sgi') diff --git a/sys/arch/sgi/sgi/lock_machdep.c b/sys/arch/sgi/sgi/lock_machdep.c index 2faa3b38fda..c2f1fc7f8d1 100644 --- a/sys/arch/sgi/sgi/lock_machdep.c +++ b/sys/arch/sgi/sgi/lock_machdep.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lock_machdep.c,v 1.1 2009/11/21 23:28:14 syuu Exp $ */ +/* $OpenBSD: lock_machdep.c,v 1.2 2010/01/26 04:56:04 miod Exp $ */ /* * Copyright (c) 2007 Artur Grabowski @@ -67,6 +67,7 @@ void __mp_lock(struct __mp_lock *mpl) { uint32_t sr; + struct cpu_info *ci = curcpu(); /* * Please notice that mpl_count gets incremented twice for the @@ -81,10 +82,12 @@ __mp_lock(struct __mp_lock *mpl) */ while (1) { sr = disableintr(); - if (__cpu_cas(&mpl->mpl_count, 0, 1) == 0) - mpl->mpl_cpu = curcpu(); + if (__cpu_cas(&mpl->mpl_count, 0, 1) == 0) { + __asm__ __volatile__ ("sync" ::: "memory"); + mpl->mpl_cpu = ci; + } - if (mpl->mpl_cpu == curcpu()) { + if (mpl->mpl_cpu == ci) { mpl->mpl_count++; setsr(sr); break; @@ -110,6 +113,7 @@ __mp_unlock(struct __mp_lock *mpl) sr = disableintr(); if (--mpl->mpl_count == 1) { mpl->mpl_cpu = NULL; + __asm__ __volatile__ ("sync" ::: "memory"); mpl->mpl_count = 0; } @@ -131,6 +135,7 @@ __mp_release_all(struct __mp_lock *mpl) sr = disableintr(); mpl->mpl_cpu = NULL; + __asm__ __volatile__ ("sync" ::: "memory"); mpl->mpl_count = 0; setsr(sr); -- cgit v1.2.3