summaryrefslogtreecommitdiffstats
path: root/lib/libpthread
diff options
context:
space:
mode:
authord <d@openbsd.org>1998-12-21 07:58:45 +0000
committerd <d@openbsd.org>1998-12-21 07:58:45 +0000
commit5a1b283044b793bc512751b0a2cb627753c58977 (patch)
tree21a3ec7d5bc9d0f89347d23cbe444e4040695821 /lib/libpthread
parentadd variable to force linkage (diff)
downloadwireguard-openbsd-5a1b283044b793bc512751b0a2cb627753c58977.tar.xz
wireguard-openbsd-5a1b283044b793bc512751b0a2cb627753c58977.zip
md spinlock
Diffstat (limited to 'lib/libpthread')
-rw-r--r--lib/libpthread/arch/i386/_atomic_lock.c25
-rw-r--r--lib/libpthread/arch/i386/_spinlock.h6
2 files changed, 19 insertions, 12 deletions
diff --git a/lib/libpthread/arch/i386/_atomic_lock.c b/lib/libpthread/arch/i386/_atomic_lock.c
index 8ddcb33068e..4794226ad3e 100644
--- a/lib/libpthread/arch/i386/_atomic_lock.c
+++ b/lib/libpthread/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/libpthread/arch/i386/_spinlock.h b/lib/libpthread/arch/i386/_spinlock.h
new file mode 100644
index 00000000000..f67c9db8eea
--- /dev/null
+++ b/lib/libpthread/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;
+