Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/sommerfeld_i386mp_1]: src/sys/arch/i386 Add barriers, just in case



details:   https://anonhg.NetBSD.org/src/rev/9bba4e9d9b9c
branches:  sommerfeld_i386mp_1
changeset: 482469:9bba4e9d9b9c
user:      sommerfeld <sommerfeld%NetBSD.org@localhost>
date:      Sat Dec 29 18:19:31 2001 +0000

description:
Add barriers, just in case

diffstat:

 sys/arch/i386/i386/lock_machdep.c |  15 +++++++++------
 sys/arch/i386/include/lock.h      |  25 ++++++++++++++++++++++---
 2 files changed, 31 insertions(+), 9 deletions(-)

diffs (121 lines):

diff -r bae09fbf7a1f -r 9bba4e9d9b9c sys/arch/i386/i386/lock_machdep.c
--- a/sys/arch/i386/i386/lock_machdep.c Fri Dec 28 06:44:13 2001 +0000
+++ b/sys/arch/i386/i386/lock_machdep.c Sat Dec 29 18:19:31 2001 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lock_machdep.c,v 1.1.2.8 2001/02/11 09:27:57 enami Exp $ */
+/* $NetBSD: lock_machdep.c,v 1.1.2.9 2001/12/29 18:20:32 sommerfeld Exp $ */
 
 /*-
  * Copyright (c) 1998, 1999 The NetBSD Foundation, Inc.
@@ -110,22 +110,25 @@
        wantlock[cpu] = 0;
        gotlock[cpu] = lockp;
 #endif
+       __lockbarrier();
 }
 
 int
 __cpu_simple_lock_try(lockp)
        __cpu_simple_lock_t *lockp;
 {
+       int r;
 #ifdef DEBUG
        __cpu_simple_lock_t v = *lockp;
 
        KDASSERT((v == __SIMPLELOCK_LOCKED) || (v == __SIMPLELOCK_UNLOCKED));
 #endif
+       r = (i386_atomic_testset_i(lockp, __SIMPLELOCK_LOCKED)
+           == __SIMPLELOCK_UNLOCKED);
 
-       if (i386_atomic_testset_i(lockp, __SIMPLELOCK_LOCKED) ==
-           __SIMPLELOCK_UNLOCKED)
-               return (1);
-       return (0);
+       __lockbarrier();
+
+       return (r);
 }
 
 void
@@ -137,7 +140,7 @@
 
        KDASSERT((v == __SIMPLELOCK_LOCKED) || (v == __SIMPLELOCK_UNLOCKED));
 #endif
-
+       __lockbarrier();
        *lockp = __SIMPLELOCK_UNLOCKED;
 }
 
diff -r bae09fbf7a1f -r 9bba4e9d9b9c sys/arch/i386/include/lock.h
--- a/sys/arch/i386/include/lock.h      Fri Dec 28 06:44:13 2001 +0000
+++ b/sys/arch/i386/include/lock.h      Sat Dec 29 18:19:31 2001 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: lock.h,v 1.1.2.5 2001/04/30 16:58:34 sommerfeld Exp $  */
+/*     $NetBSD: lock.h,v 1.1.2.6 2001/12/29 18:19:31 sommerfeld Exp $  */
 
 /*-
  * Copyright (c) 2000 The NetBSD Foundation, Inc.
@@ -52,6 +52,16 @@
 #define        __SIMPLELOCK_LOCKED     1
 #define        __SIMPLELOCK_UNLOCKED   0
 
+/*
+ * compiler barrier: prevent reordering of instructions.
+ * XXX something similar will move to <sys/cdefs.h>
+ * or thereabouts.
+ * This prevents the compiler from reordering code around
+ * this "instruction", acting as a sequence point for code generation.
+ */
+
+#define __lockbarrier() __asm __volatile("":::"memory")
+
 #ifdef LOCKDEBUG
 
 extern void __cpu_simple_lock_init __P((__cpu_simple_lock_t *));
@@ -69,35 +79,44 @@
        __attribute__((__unused__));
 static __inline int __cpu_simple_lock_try __P((__cpu_simple_lock_t *))
        __attribute__((__unused__));
-static __inline void __cpu_simple_unlock __P((__cpu_simple_lock_t *)) 
+static __inline void __cpu_simple_unlock __P((__cpu_simple_lock_t *))
        __attribute__((__unused__));
 
 static __inline void
 __cpu_simple_lock_init(__cpu_simple_lock_t *lockp)
 {
+
        *lockp = __SIMPLELOCK_UNLOCKED;
+       __lockbarrier();
 }
 
 static __inline void
 __cpu_simple_lock(__cpu_simple_lock_t *lockp)
 {
+
        while (i386_atomic_testset_i(lockp, __SIMPLELOCK_LOCKED)
            == __SIMPLELOCK_LOCKED) {
                continue;       /* spin */
        }
+       __lockbarrier();
 }
 
 static __inline int
 __cpu_simple_lock_try(__cpu_simple_lock_t *lockp)
 {
-       return (i386_atomic_testset_i(lockp, __SIMPLELOCK_LOCKED)
+       int r = (i386_atomic_testset_i(lockp, __SIMPLELOCK_LOCKED)
            == __SIMPLELOCK_UNLOCKED);
+
+       __lockbarrier();
+
+       return (r);
 }
 
 static __inline void
 __cpu_simple_unlock(__cpu_simple_lock_t *lockp)
 {
 
+       __lockbarrier();
        *lockp = __SIMPLELOCK_UNLOCKED;
 }
 



Home | Main Index | Thread Index | Old Index