Source-Changes-HG archive

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

[src/trunk]: src/sys/arch/arm/include Minor tidy-up, mostly to improve readab...



details:   https://anonhg.NetBSD.org/src/rev/4f8cc64b33c0
branches:  trunk
changeset: 537898:4f8cc64b33c0
user:      bjh21 <bjh21%NetBSD.org@localhost>
date:      Mon Oct 07 23:19:49 2002 +0000

description:
Minor tidy-up, mostly to improve readability.  The SWP instruction is now
in its own little inline function, and this allows us to get rid of all the
automatic variables elsewhere.  This subtly changes the semantics of
__cpu_simple_lock() such that the loop ends up one instruction longer, but
I'm not sure that's a particularly bad thing.

diffstat:

 sys/arch/arm/include/lock.h |  28 +++++++++++++---------------
 1 files changed, 13 insertions(+), 15 deletions(-)

diffs (56 lines):

diff -r 1e81684929e3 -r 4f8cc64b33c0 sys/arch/arm/include/lock.h
--- a/sys/arch/arm/include/lock.h       Mon Oct 07 22:46:24 2002 +0000
+++ b/sys/arch/arm/include/lock.h       Mon Oct 07 23:19:49 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: lock.h,v 1.2 2001/11/15 19:22:32 thorpej Exp $ */
+/*     $NetBSD: lock.h,v 1.3 2002/10/07 23:19:49 bjh21 Exp $   */
 
 /*-
  * Copyright (c) 2000, 2001 The NetBSD Foundation, Inc.
@@ -53,6 +53,15 @@
 #define        __SIMPLELOCK_LOCKED     1
 #define        __SIMPLELOCK_UNLOCKED   0
 
+static __inline int
+__swp(int __val, __volatile int *__ptr)
+{
+
+       __asm __volatile("swp %0, %1, [%2]"
+           : "=r" (__val) : "r" (__val), "r" (__ptr) : "memory");
+       return __val;
+}
+
 static __inline void __attribute__((__unused__))
 __cpu_simple_lock_init(__cpu_simple_lock_t *alp)
 {
@@ -63,27 +72,16 @@
 static __inline void __attribute__((__unused__))
 __cpu_simple_lock(__cpu_simple_lock_t *alp)
 {
-       int __val = __SIMPLELOCK_LOCKED;
 
-       do {
-               __asm __volatile("swp %0, %1, [%2]"
-                       : "=r" (__val)
-                       : "0" (__val), "r" (alp)
-                       : "memory");
-       } while (__val != __SIMPLELOCK_UNLOCKED);
+       while (__swp(__SIMPLELOCK_LOCKED, alp) != __SIMPLELOCK_UNLOCKED)
+               continue;
 }
 
 static __inline int __attribute__((__unused__))
 __cpu_simple_lock_try(__cpu_simple_lock_t *alp)
 {
-       int __val = __SIMPLELOCK_LOCKED;
 
-       __asm __volatile("swp %0, %1, [%2]"
-               : "=r" (__val)
-               : "0" (__val), "r" (alp)
-               : "memory");
-
-       return ((__val == __SIMPLELOCK_UNLOCKED) ? 1 : 0);
+       return (__swp(__SIMPLELOCK_LOCKED, alp) == __SIMPLELOCK_UNLOCKED);
 }
 
 static __inline void __attribute__((__unused__))



Home | Main Index | Thread Index | Old Index