summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorBrad Smith <brad@cvs.openbsd.org>2005-12-04 05:47:39 +0000
committerBrad Smith <brad@cvs.openbsd.org>2005-12-04 05:47:39 +0000
commitcec5b8977f7037d14b51384115e001d7f71ad6f7 (patch)
tree7a274f96095d08e2b746a828a292f3ede01cbd3b /lib
parent9421be7213c3c20d278191193fcd3597f370ddbd (diff)
copy alpha atomic_lock implementation from libpthread.
Diffstat (limited to 'lib')
-rw-r--r--lib/librthread/arch/alpha/_atomic_lock.S19
1 files changed, 19 insertions, 0 deletions
diff --git a/lib/librthread/arch/alpha/_atomic_lock.S b/lib/librthread/arch/alpha/_atomic_lock.S
new file mode 100644
index 00000000000..41481216c4a
--- /dev/null
+++ b/lib/librthread/arch/alpha/_atomic_lock.S
@@ -0,0 +1,19 @@
+/* $OpenBSD: _atomic_lock.S,v 1.1 2005/12/04 05:47:38 brad Exp $ */
+/* David Leonard, <d@csee.uq.edu.au>. Public domain. */
+
+#include <machine/asm.h>
+
+LEAF(_atomic_lock,1)
+ LDGP(pv)
+
+ /* NOTE: using ldl_l/stl_c instead of
+ ldq_l and ldq_c as machine/spinlock.h
+ defines _spinlock_lock_t as int */
+0: ldl_l v0, 0(a0) /* read existing lock value */
+ mov 1, t0 /* locked value to store */
+ stl_c t0, 0(a0) /* attempt to store, status in t0 */
+ beq t0, 1f /* branch forward to optimise prediction */
+ mb /* sync with other processors */
+ RET /* return with v0==0 if lock obtained */
+1: br 0b /* loop to try again */
+END(_atomic_lock)