diff options
author | 1998-12-21 07:58:45 +0000 | |
---|---|---|
committer | 1998-12-21 07:58:45 +0000 | |
commit | 5a1b283044b793bc512751b0a2cb627753c58977 (patch) | |
tree | 21a3ec7d5bc9d0f89347d23cbe444e4040695821 /lib/libpthread/arch/i386/_atomic_lock.c | |
parent | add variable to force linkage (diff) | |
download | wireguard-openbsd-5a1b283044b793bc512751b0a2cb627753c58977.tar.xz wireguard-openbsd-5a1b283044b793bc512751b0a2cb627753c58977.zip |
md spinlock
Diffstat (limited to 'lib/libpthread/arch/i386/_atomic_lock.c')
-rw-r--r-- | lib/libpthread/arch/i386/_atomic_lock.c | 25 |
1 files changed, 13 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); } |