Add the DragonFly cvs id and perform general cleanups on cvs/rcs/sccs ids. Most
[dragonfly.git] / lib / libc_r / arch / alpha / _atomic_lock.S
1 /*
2  * Copyright (c) 1998 John Birrell <jb@cimlogic.com.au>.
3  * All rights reserved.
4  * copyright Douglas Santry 1996
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the above copyright is retained
8  * in the source form.
9  *
10  * THIS SOFTWARE IS PROVIDED BY Douglas Santry AND CONTRIBUTORS ``AS IS'' AND
11  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE  
12  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE   
13  * ARE DISCLAIMED.  IN NO EVENT SHALL Douglas Santry OR CONTRIBUTORS BE LIABLE 
14  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL   
15  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS      
16  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
17  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
18  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 
19  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF  
20  * SUCH DAMAGE.    
21  *
22  * $FreeBSD: src/lib/libc_r/arch/alpha/_atomic_lock.S,v 1.3 1999/08/28 00:03:00 peter Exp $
23  * $DragonFly: src/lib/libc_r/arch/alpha/Attic/_atomic_lock.S,v 1.2 2003/06/17 04:26:47 dillon Exp $
24  *
25  */
26
27 #include "SYS.h"
28
29 /*
30  * Atomicly lock a location with an identifier provided the location
31  * is not currently locked.
32  *
33  * long _atomic_lock(long *);
34  * v0 will contain the return value (zero if lock obtained).
35  */
36 LEAF(_atomic_lock,0)
37         LDGP(pv)
38
39 0:      ldq_l   v0, 0(a0)       /* read existing lock value */
40         mov     1, t0           /* locked value to store */
41         stq_c   t0, 0(a0)       /* attempt to store, status in t0 */
42         beq     t0, 1f          /* branch foward to optimise prediction */
43         mb                      /* sync with other processors */
44         RET                     /* return with v0==0 if lock obtained */
45 1:      br      0b              /* loop to try again */
46 END(_atomic_lock)