summaryrefslogtreecommitdiffstats
path: root/lib/libpthread/arch
diff options
context:
space:
mode:
authord <d@openbsd.org>1998-12-21 07:36:58 +0000
committerd <d@openbsd.org>1998-12-21 07:36:58 +0000
commit7e271bc515f3a7cb809aafa70bda90a7af35f077 (patch)
tree78eaf0f7aa731fc84022d1ad2f3f30e227b31175 /lib/libpthread/arch
parentclean (diff)
downloadwireguard-openbsd-7e271bc515f3a7cb809aafa70bda90a7af35f077.tar.xz
wireguard-openbsd-7e271bc515f3a7cb809aafa70bda90a7af35f077.zip
md spinlock
Diffstat (limited to 'lib/libpthread/arch')
-rw-r--r--lib/libpthread/arch/alpha/_atomic_lock.c20
-rw-r--r--lib/libpthread/arch/alpha/_spinlock.h6
-rw-r--r--lib/libpthread/arch/m68k/_atomic_lock.c20
-rw-r--r--lib/libpthread/arch/m68k/_spinlock.h6
-rw-r--r--lib/libpthread/arch/mips/_atomic_lock.c28
-rw-r--r--lib/libpthread/arch/mips/_spinlock.h6
-rw-r--r--lib/libpthread/arch/sparc/_atomic_lock.c4
-rw-r--r--lib/libpthread/arch/sparc/_spinlock.h6
8 files changed, 62 insertions, 34 deletions
diff --git a/lib/libpthread/arch/alpha/_atomic_lock.c b/lib/libpthread/arch/alpha/_atomic_lock.c
index b12bc32d94a..75aace9532c 100644
--- a/lib/libpthread/arch/alpha/_atomic_lock.c
+++ b/lib/libpthread/arch/alpha/_atomic_lock.c
@@ -1,42 +1,42 @@
-/* $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:36:59 d Exp $ */
/*
* Atomic lock for alpha
*/
#include "spinlock.h"
-register_t
-_atomic_lock(volatile register_t * lock)
+int
+_atomic_lock(volatile _spinlock_lock_t * lock)
{
- register_t old;
- register_t new;
+ _spinlock_lock_t old;
+ _spinlock_lock_t new;
int success;
do {
/* load the value of the thread-lock (lock mem on load) */
__asm__( "ldq_l %0, %1" : "=r"(old) : "m"(*lock) );
if (old)
- new = old; /* in-use: put it back */
+ new = old; /* locked: no change */
else
- new = 1; /* free: store a 1 in the lock */
+ new = _SPINLOCK_LOCKED; /* unlocked: grab it */
success = 0;
/* store the new value of the thrd-lock (unlock mem on store) */
/*
* XXX may need to add large branch forward for main line
- * branch prediction to be right :(
+ * branch prediction to be right :( [note from linux]
*/
__asm__( "stq_c %2, %0; beq %2, 1f; mov 1,%1; 1:"
: "=m"(*lock), "=r"(success)
: "r"(new) );
} while (!success);
- return old;
+ return (old != _SPINLOCK_UNLOCKED);
}
int
_atomic_is_locked(volatile register_t * lock)
{
- return *lock;
+ return (*lock != _SPINLOCK_UNLOCKED);
}
diff --git a/lib/libpthread/arch/alpha/_spinlock.h b/lib/libpthread/arch/alpha/_spinlock.h
new file mode 100644
index 00000000000..259260c28a0
--- /dev/null
+++ b/lib/libpthread/arch/alpha/_spinlock.h
@@ -0,0 +1,6 @@
+/* $OpenBSD: _spinlock.h,v 1.1 1998/12/21 07:36:59 d Exp $ */
+
+#define _SPINLOCK_UNLOCKED (0)
+#define _SPINLOCK_LOCKED (1)
+typedef int _spinlock_lock_t;
+
diff --git a/lib/libpthread/arch/m68k/_atomic_lock.c b/lib/libpthread/arch/m68k/_atomic_lock.c
index d0e2ddbe2d6..9a59370c375 100644
--- a/lib/libpthread/arch/m68k/_atomic_lock.c
+++ b/lib/libpthread/arch/m68k/_atomic_lock.c
@@ -1,14 +1,14 @@
-/* $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:36:59 d Exp $ */
/*
* Atomic lock for m68k
*/
#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;
/*
* The Compare And Swap instruction (mc68020 and above)
@@ -19,17 +19,17 @@ _atomic_lock(volatile register_t *lock)
*
* old = 0;
* CAS(old, 1, *lock);
- * return old;
+ * if (old == 1) { lock was acquired }
*/
- old = 0;
+ old = _SPINLOCK_UNLOCKED;
__asm__("casl %0, %2, %1" : "=d"(old), "=m"(*lock)
- : "d"(1), "0"(old));
- return old;
+ : "d"(_SPINLOCK_LOCKED), "0"(old));
+ return (old != _SPINLOCK_UNLOCKED);
}
int
-_atomic_lock(volatile register_t *lock)
+_atomic_lock(volatile _spinlock_lock_t *lock)
{
- return *lock;
+ return (*lock != _SPINLOCK_UNLOCKED);
}
diff --git a/lib/libpthread/arch/m68k/_spinlock.h b/lib/libpthread/arch/m68k/_spinlock.h
new file mode 100644
index 00000000000..06f9ffeb540
--- /dev/null
+++ b/lib/libpthread/arch/m68k/_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;
+
diff --git a/lib/libpthread/arch/mips/_atomic_lock.c b/lib/libpthread/arch/mips/_atomic_lock.c
index 4df2a99ad85..6961a679069 100644
--- a/lib/libpthread/arch/mips/_atomic_lock.c
+++ b/lib/libpthread/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/libpthread/arch/mips/_spinlock.h b/lib/libpthread/arch/mips/_spinlock.h
new file mode 100644
index 00000000000..06f9ffeb540
--- /dev/null
+++ b/lib/libpthread/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;
+
diff --git a/lib/libpthread/arch/sparc/_atomic_lock.c b/lib/libpthread/arch/sparc/_atomic_lock.c
index 530c86b4805..31636328f93 100644
--- a/lib/libpthread/arch/sparc/_atomic_lock.c
+++ b/lib/libpthread/arch/sparc/_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:01 d Exp $ */
/*
* Atomic lock for sparc
*/
@@ -15,5 +15,5 @@ int
_atomic_is_locked(volatile register_t * lock)
{
- return *lock;
+ return _thread_slow_atomic_is_locked(lock);
}
diff --git a/lib/libpthread/arch/sparc/_spinlock.h b/lib/libpthread/arch/sparc/_spinlock.h
new file mode 100644
index 00000000000..87b8e5485e3
--- /dev/null
+++ b/lib/libpthread/arch/sparc/_spinlock.h
@@ -0,0 +1,6 @@
+/* $OpenBSD: _spinlock.h,v 1.1 1998/12/21 07:37:01 d Exp $ */
+
+#define _SPINLOCK_UNLOCKED (0)
+#define _SPINLOCK_LOCKED (1)
+typedef int _spinlock_lock_t;
+