Source-Changes-HG archive

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

[src/trunk]: src/sys/arch/riscv/include Use C11 atomic builtins instead of __...



details:   https://anonhg.NetBSD.org/src/rev/a182e3623ffc
branches:  trunk
changeset: 807122:a182e3623ffc
user:      matt <matt%NetBSD.org@localhost>
date:      Sun Mar 29 09:43:26 2015 +0000

description:
Use C11 atomic builtins instead of __asm.

diffstat:

 sys/arch/riscv/include/lock.h |  50 +++++++++++-------------------------------
 1 files changed, 13 insertions(+), 37 deletions(-)

diffs (97 lines):

diff -r 95719b88e9d3 -r a182e3623ffc sys/arch/riscv/include/lock.h
--- a/sys/arch/riscv/include/lock.h     Sun Mar 29 05:52:59 2015 +0000
+++ b/sys/arch/riscv/include/lock.h     Sun Mar 29 09:43:26 2015 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lock.h,v 1.1 2014/09/19 17:36:26 matt Exp $ */
+/* $NetBSD: lock.h,v 1.2 2015/03/29 09:43:26 matt Exp $ */
 
 /*-
  * Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -50,75 +50,51 @@
 static __inline void
 __cpu_simple_lock_clear(__cpu_simple_lock_t *__ptr)
 {
-#if 0
-       __atomic_clear(__ptr, __ATOMIC_RELAXED);
+#if 1
+       *__ptr = __SIMPLELOCK_UNLOCKED;
 #else
-       *__ptr = __SIMPLELOCK_UNLOCKED;
+       __atomic_store_n(__ptr, __SIMPLELOCK_UNLOCKED, __ATOMIC_RELAXED);
 #endif
 }
 
 static __inline void
 __cpu_simple_lock_set(__cpu_simple_lock_t *__ptr)
 {
-#if 0
-       (void)__atomic_test_and_set(__ptr, __ATOMIC_RELAXED);
+#if 1
+       *__ptr = __SIMPLELOCK_LOCKED;
 #else
-       *__ptr = __SIMPLELOCK_LOCKED;
+       __atomic_store_n(__ptr, __SIMPLELOCK_LOCKED, __ATOMIC_RELAXED);
 #endif
 }
 
 static __inline void __unused
 __cpu_simple_lock_init(__cpu_simple_lock_t *__ptr)
 {
-#if 0
-       __atomic_clear(__ptr, __ATOMIC_RELAXED);
+#if 1
+       *__ptr = __SIMPLELOCK_UNLOCKED;
 #else
-       *__ptr = __SIMPLELOCK_UNLOCKED;
+       __atomic_store_n(__ptr, __SIMPLELOCK_UNLOCKED, __ATOMIC_RELAXED);
 #endif
 }
 
 static __inline void __unused
 __cpu_simple_lock(__cpu_simple_lock_t *__ptr)
 {
-#if 0
-       while (__atomic_test_and_set(__ptr, __ATOMIC_ACQUIRE)) {
+       while (__atomic_exchange_n(__ptr, __SIMPLELOCK_LOCKED, __ATOMIC_ACQUIRE) == __SIMPLELOCK_LOCKED) {
                /* do nothing */
        }
-#else
-       int __tmp;
-       __asm(
-       "\n"    "1:"
-       "\n\t"  "amoswap.w.aq   %[__tmp], %[__newval], 0(%[__ptr])"
-       "\n\t"  "bnez           %[__tmp], 1b"
-          :    [__tmp] "=&r" (__tmp)
-          :    [__newval] "r" (__SIMPLELOCK_LOCKED),
-               [__ptr] "r" (__ptr));
-#endif
 }
 
 static __inline int __unused
 __cpu_simple_lock_try(__cpu_simple_lock_t *__ptr)
 {
-#if 0
-       return !__atomic_test_and_set(__ptr, __ATOMIC_ACQUIRE);
-#else
-       int __oldval;
-       __asm(  "amoswap.w.aq\t%[__oldval], %[__newval], 0(%[__ptr])"
-          :    [__oldval] "=r" (__oldval)
-          :    [__newval] "r" (__SIMPLELOCK_LOCKED),
-               [__ptr] "r" (__ptr));
-       return __oldval == __SIMPLELOCK_UNLOCKED;
-#endif
+       return __atomic_exchange_n(__ptr, __SIMPLELOCK_LOCKED, __ATOMIC_ACQUIRE) == __SIMPLELOCK_LOCKED;
 }
 
 static __inline void __unused
 __cpu_simple_unlock(__cpu_simple_lock_t *__ptr)
 {
-#if 0
-       __atomic_clear(__ptr, __ATOMIC_RELEASE);
-#else
-       __asm("amoswap.w.rl\tx0, x0, 0(%[__ptr])" :: [__ptr] "r" (__ptr));
-#endif
+       __atomic_store_n(__ptr, __SIMPLELOCK_UNLOCKED, __ATOMIC_RELEASE);
 }
 
 #endif /* _RISCV_LOCK_H_ */



Home | Main Index | Thread Index | Old Index