summaryrefslogtreecommitdiff
path: root/lib/libc_r/arch/i386/_atomic_lock.c
diff options
context:
space:
mode:
authorDavid Leonard <d@cvs.openbsd.org>1998-11-20 11:15:39 +0000
committerDavid Leonard <d@cvs.openbsd.org>1998-11-20 11:15:39 +0000
commit394c7a9821726b84f284c0c4385b1a9198afa0b0 (patch)
treee3fcaf31862eb53986f206217f7986fe433c6ce7 /lib/libc_r/arch/i386/_atomic_lock.c
parentd2d530d679e5709dfdaa5ea40bea4a4d25694930 (diff)
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/libc_r/arch/i386/_atomic_lock.c')
-rw-r--r--lib/libc_r/arch/i386/_atomic_lock.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/lib/libc_r/arch/i386/_atomic_lock.c b/lib/libc_r/arch/i386/_atomic_lock.c
new file mode 100644
index 00000000000..609dc42fb01
--- /dev/null
+++ b/lib/libc_r/arch/i386/_atomic_lock.c
@@ -0,0 +1,26 @@
+/* $OpenBSD: _atomic_lock.c,v 1.1 1998/11/20 11:15:36 d Exp $ */
+/*
+ * Atomic lock aquire for i386.
+ */
+
+#include "spinlock.h"
+
+register_t
+_atomic_lock(volatile register_t *lock)
+{
+ register_t old;
+
+ /*
+ * Use the eXCHanGe instruction to swap the lock value with
+ * a local variable containg '1' (the locked state).
+ */
+ old = 1;
+ __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.
+ */
+ return old;
+}