diff options
author | 1998-12-21 07:36:58 +0000 | |
---|---|---|
committer | 1998-12-21 07:36:58 +0000 | |
commit | 7e271bc515f3a7cb809aafa70bda90a7af35f077 (patch) | |
tree | 78eaf0f7aa731fc84022d1ad2f3f30e227b31175 /lib/libpthread | |
parent | clean (diff) | |
download | wireguard-openbsd-7e271bc515f3a7cb809aafa70bda90a7af35f077.tar.xz wireguard-openbsd-7e271bc515f3a7cb809aafa70bda90a7af35f077.zip |
md spinlock
Diffstat (limited to 'lib/libpthread')
-rw-r--r-- | lib/libpthread/arch/alpha/_atomic_lock.c | 20 | ||||
-rw-r--r-- | lib/libpthread/arch/alpha/_spinlock.h | 6 | ||||
-rw-r--r-- | lib/libpthread/arch/m68k/_atomic_lock.c | 20 | ||||
-rw-r--r-- | lib/libpthread/arch/m68k/_spinlock.h | 6 | ||||
-rw-r--r-- | lib/libpthread/arch/mips/_atomic_lock.c | 28 | ||||
-rw-r--r-- | lib/libpthread/arch/mips/_spinlock.h | 6 | ||||
-rw-r--r-- | lib/libpthread/arch/sparc/_atomic_lock.c | 4 | ||||
-rw-r--r-- | lib/libpthread/arch/sparc/_spinlock.h | 6 | ||||
-rw-r--r-- | lib/libpthread/sys/slow_atomic_lock.c | 21 |
9 files changed, 76 insertions, 41 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; + diff --git a/lib/libpthread/sys/slow_atomic_lock.c b/lib/libpthread/sys/slow_atomic_lock.c index ca86bb3dd52..22889ea8691 100644 --- a/lib/libpthread/sys/slow_atomic_lock.c +++ b/lib/libpthread/sys/slow_atomic_lock.c @@ -1,4 +1,4 @@ -/* $OpenBSD: slow_atomic_lock.c,v 1.2 1998/11/21 14:02:10 d Exp $ */ +/* $OpenBSD: slow_atomic_lock.c,v 1.3 1998/12/21 07:38:43 d Exp $ */ #include <pthread.h> #include "pthread_private.h" @@ -12,10 +12,10 @@ * This uses signal masking to make sure that no other thread * can modify the lock while processing, hence it is very slow. */ -register_t -_thread_slow_atomic_lock(volatile register_t *lock) +int +_thread_slow_atomic_lock(volatile _spinlock_lock_t *lock) { - register_t old; + _spinlock_lock_t old; sigset_t oldset, newset = (sigset_t)~0; /* block signals - incurs a context switch */ @@ -23,12 +23,19 @@ _thread_slow_atomic_lock(volatile register_t *lock) PANIC("_atomic_lock block"); old = *lock; - if (old == 0) - *lock = 1; + if (old == _SPINLOCK_UNLOCKED) + *lock = _SPINLOCK_LOCKED; /* restore signal mask to what it was */ if (_thread_sys_sigprocmask(SIG_SETMASK, &oldset, NULL) < 0) PANIC("_atomic_lock restore"); - return old; + return (old != _SPINLOCK_UNLOCKED); +} + +int +_thread_slow_atomic_is_locked(volatile _spinlock_lock_t *lock) +{ + + return (*lock != _SPINLOCK_UNLOCKED); } |