summaryrefslogtreecommitdiff
path: root/lib/libc_r/arch
diff options
context:
space:
mode:
authorDavid Leonard <d@cvs.openbsd.org>1998-12-21 07:58:46 +0000
committerDavid Leonard <d@cvs.openbsd.org>1998-12-21 07:58:46 +0000
commit4014986dea1041fdcec7bb6175a3f8281f782130 (patch)
treef44c9774ee1c17ab816fae4ff47d6f2e50143ac7 /lib/libc_r/arch
parent0c6d2e95c92c40573878f74275b2e425e727b076 (diff)
md spinlock
Diffstat (limited to 'lib/libc_r/arch')
-rw-r--r--lib/libc_r/arch/i386/_atomic_lock.c25
-rw-r--r--lib/libc_r/arch/i386/_spinlock.h6
2 files changed, 19 insertions, 12 deletions
diff --git a/lib/libc_r/arch/i386/_atomic_lock.c b/lib/libc_r/arch/i386/_atomic_lock.c
index 8ddcb33068e..4794226ad3e 100644
--- a/lib/libc_r/arch/i386/_atomic_lock.c
+++ b/lib/libc_r/arch/i386/_atomic_lock.c
@@ -1,33 +1,34 @@
-/* $OpenBSD: _atomic_lock.c,v 1.2 1998/12/18 05:59:17 d Exp $ */
+/* $OpenBSD: _atomic_lock.c,v 1.3 1998/12/21 07:58:45 d Exp $ */
/*
* Atomic lock for i386
*/
#include "spinlock.h"
-register_t
-_atomic_lock(volatile register_t *lock)
+int
+_atomic_lock(volatile _spinlock_lock_t *lock)
{
- register_t old;
+ _spinlock_lock_t old;
/*
* Use the eXCHanGe instruction to swap the lock value with
- * a local variable containg '1' (the locked state).
+ * a local variable containg the locked state.
*/
- old = 1;
+ old = _SPINLOCK_LOCKED;
__asm__("xchg %0, %1"
: "=r" (old), "=m" (*lock) : "0"(old), "1" (*lock) );
/*
- * So now there is a 1 in *lock and 'old' contains what
- * used to be in the lock. We return 0 if the lock was acquired,
- * (ie its old value was 0) or 1 otherwise.
+ * So now LOCKED is in *lock and 'old' contains what
+ * used to be in *lock. We return 0 if the lock was acquired,
+ * (ie its old value was UNLOCKED) or 1 otherwise.
*/
- return old;
+ return (old != _SPINLOCK_UNLOCKED);
}
int
-_atomic_is_locked(volatile register_t *lock)
+_atomic_is_locked(volatile _spinlock_lock_t *lock)
{
- return *lock;
+ /* Return true if the lock is locked (i.e., is not unlocked). */
+ return (*lock != _SPINLOCK_UNLOCKED);
}
diff --git a/lib/libc_r/arch/i386/_spinlock.h b/lib/libc_r/arch/i386/_spinlock.h
new file mode 100644
index 00000000000..f67c9db8eea
--- /dev/null
+++ b/lib/libc_r/arch/i386/_spinlock.h
@@ -0,0 +1,6 @@
+/* $OpenBSD: _spinlock.h,v 1.1 1998/12/21 07:58:45 d Exp $ */
+
+#define _SPINLOCK_UNLOCKED (0)
+#define _SPINLOCK_LOCKED (1)
+typedef int _spinlock_lock_t;
+