summaryrefslogtreecommitdiff
path: root/lib/libc_r/arch/mips
diff options
context:
space:
mode:
authorDavid Leonard <d@cvs.openbsd.org>1998-12-21 07:37:02 +0000
committerDavid Leonard <d@cvs.openbsd.org>1998-12-21 07:37:02 +0000
commitb3d4268288925fddfedfa142adcf20c98fb7fc48 (patch)
treede1ca6f15aebff9abb87d6a5edb96455807a752e /lib/libc_r/arch/mips
parent66bdaa1f5ea7558365a91a75db751c76275ebce2 (diff)
md spinlock
Diffstat (limited to 'lib/libc_r/arch/mips')
-rw-r--r--lib/libc_r/arch/mips/_atomic_lock.c28
-rw-r--r--lib/libc_r/arch/mips/_spinlock.h6
2 files changed, 22 insertions, 12 deletions
diff --git a/lib/libc_r/arch/mips/_atomic_lock.c b/lib/libc_r/arch/mips/_atomic_lock.c
index 4df2a99ad85..6961a679069 100644
--- a/lib/libc_r/arch/mips/_atomic_lock.c
+++ b/lib/libc_r/arch/mips/_atomic_lock.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: _atomic_lock.c,v 1.2 1998/12/18 05:59:18 d Exp $ */
+/* $OpenBSD: _atomic_lock.c,v 1.3 1998/12/21 07:37:00 d Exp $ */
/*
* Atomic lock for mips
*/
@@ -12,12 +12,12 @@
* attempt to acquire a lock (by giving it a non-zero value).
* Return zero on success, or the lock's value on failure
*/
-register_t
-_atomic_lock(volatile register_t *lock)
+int
+_atomic_lock(volatile _spinlock_lock_t *lock)
{
- register_t old;
#if __mips >= 2
- register_t temp;
+ _spinlock_lock_t old;
+ _spinlock_lock_t temp;
do {
/*
@@ -27,7 +27,7 @@ _atomic_lock(volatile register_t *lock)
* physical address of lock for diagnostic purposes);
*/
__asm__("ll %0, %1" : "=r"(old) : "m"(*lock));
- if (old)
+ if (old != _SPINLOCK_UNLOCKED)
break; /* already locked */
/*
* Try and store a 1 at the tagged lock address. If
@@ -35,25 +35,29 @@ _atomic_lock(volatile register_t *lock)
* line will have been wiped, and temp will be set to zero
* by the 'store conditional' instruction.
*/
- temp = 1;
+ temp = _SPINLOCK_LOCKED;
__asm__("sc %0, %1" : "=r"(temp), "=m"(*lock)
: "0"(temp));
} while (temp == 0);
+
+ return (old != _SPINLOCK_UNLOCKED);
#else
/*
* Older MIPS cpus have no way of doing an atomic lock
* without some kind of shift to supervisor mode.
*/
- old = _thread_slow_atomic_lock(lock);
-
+ return (_thread_slow_atomic_lock(lock));
#endif
- return old;
}
int
-_atomic_is_locked(volatile register_t * lock)
+_atomic_is_locked(volatile register_t *lock)
{
- return *lock;
+#if __mips >= 2
+ return (*lock != _SPINLOCK_UNLOCKED);
+#else
+ return (_thread_slow_atomic_is_locked(lock));
+#endif
}
diff --git a/lib/libc_r/arch/mips/_spinlock.h b/lib/libc_r/arch/mips/_spinlock.h
new file mode 100644
index 00000000000..06f9ffeb540
--- /dev/null
+++ b/lib/libc_r/arch/mips/_spinlock.h
@@ -0,0 +1,6 @@
+/* $OpenBSD: _spinlock.h,v 1.1 1998/12/21 07:37:00 d Exp $ */
+
+#define _SPINLOCK_UNLOCKED (0)
+#define _SPINLOCK_LOCKED (1)
+typedef int _spinlock_lock_t;
+