diff options
author | David Leonard <d@cvs.openbsd.org> | 1998-12-21 07:22:27 +0000 |
---|---|---|
committer | David Leonard <d@cvs.openbsd.org> | 1998-12-21 07:22:27 +0000 |
commit | 21f0fd70f7fdd97dbfd9a4962cbcded9833a6c2f (patch) | |
tree | 96808755b4aaf142df62f4203d5904c9bc05584c /lib/libc_r/arch/powerpc/_atomic_lock.c | |
parent | a0089315910b3609b141f3e965cc2ac806fcc567 (diff) |
unfinished powerpc md stuff.. rahnds?
Diffstat (limited to 'lib/libc_r/arch/powerpc/_atomic_lock.c')
-rw-r--r-- | lib/libc_r/arch/powerpc/_atomic_lock.c | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/lib/libc_r/arch/powerpc/_atomic_lock.c b/lib/libc_r/arch/powerpc/_atomic_lock.c new file mode 100644 index 00000000000..ab1a5321763 --- /dev/null +++ b/lib/libc_r/arch/powerpc/_atomic_lock.c @@ -0,0 +1,43 @@ +/* $OpenBSD: _atomic_lock.c,v 1.1 1998/12/21 07:22:26 d Exp $ */ +/* + * Atomic lock for powerpc + */ + +#include "spinlock.h" + +int +_atomic_lock(volatile _spinlock_lock_t *lock) +{ + _spinlock_lock_t old; + + __asm__("1: lwarx %0,0,%1 \n" + " stwcx. %2,0,%1 \n" + " bne- 1b \n" + : "=r" (old), "=r" (lock) + : "r" (_SPINLOCK_LOCKED), "1" (lock) + ); + + return (old != _SPINLOCK_UNLOCKED); + + /* + * Dale <rahnds@openbsd.org> sez: + * Side note. to prevent two processes from accessing + * the same address with the lwarx in one instrution + * and the stwcx in another process, the current powerpc + * kernel uses a lwarx instruction without the corresponding + * stwcx which effectively causes any reservation of a + * process to be removed. if a context switch occurs + * between the two accesses the store will not occur + * and the condition code will cause it to loop. If on + * a dual processor machine, the reserve will cause + * appropriate bus cycle accesses to notify other + * processors. + */ +} + +int +_atomic_is_locked(volatile _spinlock_lock_t *lock) +{ + + return (*lock != _SPINLOCK_UNLOCKED); +} |