diff options
author | David Leonard <d@cvs.openbsd.org> | 1998-11-20 11:15:39 +0000 |
---|---|---|
committer | David Leonard <d@cvs.openbsd.org> | 1998-11-20 11:15:39 +0000 |
commit | 394c7a9821726b84f284c0c4385b1a9198afa0b0 (patch) | |
tree | e3fcaf31862eb53986f206217f7986fe433c6ce7 /lib/libpthread/arch/alpha | |
parent | d2d530d679e5709dfdaa5ea40bea4a4d25694930 (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/libpthread/arch/alpha')
-rw-r--r-- | lib/libpthread/arch/alpha/_atomic_lock.S | 58 | ||||
-rw-r--r-- | lib/libpthread/arch/alpha/_atomic_lock.c | 33 |
2 files changed, 33 insertions, 58 deletions
diff --git a/lib/libpthread/arch/alpha/_atomic_lock.S b/lib/libpthread/arch/alpha/_atomic_lock.S deleted file mode 100644 index ba0022e4a4d..00000000000 --- a/lib/libpthread/arch/alpha/_atomic_lock.S +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (c) 1998 John Birrell <jb@cimlogic.com.au>. - * All rights reserved. - * copyright Douglas Santry 1996 - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the above copyright is retained - * in the source form. - * - * THIS SOFTWARE IS PROVIDED BY Douglas Santry AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL Douglas Santry OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $Id: _atomic_lock.S,v 1.1 1998/08/28 01:54:57 d Exp $ - * $OpenBSD: _atomic_lock.S,v 1.1 1998/08/28 01:54:57 d Exp $ - * - */ - -#include "SYS.h" - -/* - * Atomicly lock a location with an identifier provided the location - * is not currently locked. - * - * long _atomic_lock(long *); - * v0 will contain the return value (zero if lock obtained). - */ -LEAF(_atomic_lock,0) - LDGP(pv) - - /* Get the existing lock value and lock memory: */ - ldq_l v0, 0(a0) - - /* Branch if already locked: */ - bne v0, already_locked - - /* Not locked, so store 1: */ - mov 1, t0 - stq_c t0, 0(a0) - - /* Obtained the lock: */ - br done - -already_locked: - /* Already locked so put the value back and unlock memory: */ - stq_c v0, 0(a0) - -done: - RET -END(_atomic_lock) diff --git a/lib/libpthread/arch/alpha/_atomic_lock.c b/lib/libpthread/arch/alpha/_atomic_lock.c new file mode 100644 index 00000000000..74575fc11d7 --- /dev/null +++ b/lib/libpthread/arch/alpha/_atomic_lock.c @@ -0,0 +1,33 @@ +/* $OpenBSD: _atomic_lock.c,v 1.1 1998/11/20 11:15:35 d Exp $ */ +/* Atomic lock for alpha */ + +#include "spinlock.h" + +register_t +_atomic_lock(volatile register_t * lock) +{ + register_t old; + register_t new; + int success; + + do { + /* load the value of the thread-lock (lock mem on load) */ + __asm__( "ldq_l %0, %1" : "=r"(old) : "m"(*lock) ); + if (old) + new = old; /* in-use: put it back */ + else + new = 1; /* free: store a 1 in the lock */ + + success = 0; + /* store the new value of the thrd-lock (unlock mem on store) */ + /* + * XXX may need to add large branch forward for main line + * branch prediction to be right :( + */ + __asm__( "stq_c %2, %0; beq %2, 1f; mov 1,%1; 1:" + : "=m"(*lock), "=r"(success) + : "r"(new) ); + } while (!success); + + return old; +} |