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.
This commit is contained in:
bjh21 2002-10-07 23:19:49 +00:00
parent 92184041d7
commit 5a9767e3de
1 changed files with 13 additions and 15 deletions

View File

@ -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. * Copyright (c) 2000, 2001 The NetBSD Foundation, Inc.
@ -53,6 +53,15 @@ typedef __volatile int __cpu_simple_lock_t;
#define __SIMPLELOCK_LOCKED 1 #define __SIMPLELOCK_LOCKED 1
#define __SIMPLELOCK_UNLOCKED 0 #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__)) static __inline void __attribute__((__unused__))
__cpu_simple_lock_init(__cpu_simple_lock_t *alp) __cpu_simple_lock_init(__cpu_simple_lock_t *alp)
{ {
@ -63,27 +72,16 @@ __cpu_simple_lock_init(__cpu_simple_lock_t *alp)
static __inline void __attribute__((__unused__)) static __inline void __attribute__((__unused__))
__cpu_simple_lock(__cpu_simple_lock_t *alp) __cpu_simple_lock(__cpu_simple_lock_t *alp)
{ {
int __val = __SIMPLELOCK_LOCKED;
do { while (__swp(__SIMPLELOCK_LOCKED, alp) != __SIMPLELOCK_UNLOCKED)
__asm __volatile("swp %0, %1, [%2]" continue;
: "=r" (__val)
: "0" (__val), "r" (alp)
: "memory");
} while (__val != __SIMPLELOCK_UNLOCKED);
} }
static __inline int __attribute__((__unused__)) static __inline int __attribute__((__unused__))
__cpu_simple_lock_try(__cpu_simple_lock_t *alp) __cpu_simple_lock_try(__cpu_simple_lock_t *alp)
{ {
int __val = __SIMPLELOCK_LOCKED;
__asm __volatile("swp %0, %1, [%2]" return (__swp(__SIMPLELOCK_LOCKED, alp) == __SIMPLELOCK_UNLOCKED);
: "=r" (__val)
: "0" (__val), "r" (alp)
: "memory");
return ((__val == __SIMPLELOCK_UNLOCKED) ? 1 : 0);
} }
static __inline void __attribute__((__unused__)) static __inline void __attribute__((__unused__))