summaryrefslogtreecommitdiffstats
path: root/lib/libpthread/arch/m68k/_atomic_lock.c
diff options
context:
space:
mode:
authord <d@openbsd.org>1998-11-20 11:15:35 +0000
committerd <d@openbsd.org>1998-11-20 11:15:35 +0000
commitea03e63fbd0d2b427542c2481ae506ce9e278791 (patch)
tree6a43235671adbd8289e0d0a14275441a0d653748 /lib/libpthread/arch/m68k/_atomic_lock.c
parentfix strcat usage; deraadt (diff)
downloadwireguard-openbsd-ea03e63fbd0d2b427542c2481ae506ce9e278791.tar.xz
wireguard-openbsd-ea03e63fbd0d2b427542c2481ae506ce9e278791.zip
Move atomic_lock code from asm to C with inline asm;
Add m68k, mips and sparc. (needs more careful checking) Add 'slow_atomic_lock' for crippled archs.
Diffstat (limited to 'lib/libpthread/arch/m68k/_atomic_lock.c')
-rw-r--r--lib/libpthread/arch/m68k/_atomic_lock.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/lib/libpthread/arch/m68k/_atomic_lock.c b/lib/libpthread/arch/m68k/_atomic_lock.c
new file mode 100644
index 00000000000..be874ad2892
--- /dev/null
+++ b/lib/libpthread/arch/m68k/_atomic_lock.c
@@ -0,0 +1,27 @@
+/* $OpenBSD: _atomic_lock.c,v 1.1 1998/11/20 11:15:36 d Exp $ */
+/*
+ * Atomic lock for m68k
+ */
+#include "spinlock.h"
+
+register_t
+_atomic_lock(volatile register_t *lock)
+{
+ register_t old;
+
+ /*
+ * The Compare And Swap instruction (mc68020 and above)
+ * compares its first operand with the memory addressed by
+ * the third. If they are the same value, the second operand
+ * is stored at the address. Otherwise the 1st operand (register)
+ * is loaded with the contents of the 3rd operand.
+ *
+ * old = 0;
+ * CAS(old, 1, *lock);
+ * return old;
+ */
+ old = 0;
+ __asm__("casl %0, %2, %1" : "=d"(old), "=m"(*lock)
+ : "d"(1), "0"(old));
+ return old;
+}