xref: /openbsd-src/lib/libc/arch/m88k/gen/_atomic_lock.c (revision 7e321ac128fdcd388c62dfa54aca790ebbd73ce1)
1*7e321ac1Sguenther /*	$OpenBSD: _atomic_lock.c,v 1.1 2017/08/15 06:13:24 guenther Exp $	*/
2*7e321ac1Sguenther 
3*7e321ac1Sguenther /*
4*7e321ac1Sguenther  * Copyright (c) 2003, Miodrag Vallat.
5*7e321ac1Sguenther  *
6*7e321ac1Sguenther  * Redistribution and use in source and binary forms, with or without
7*7e321ac1Sguenther  * modification, are permitted provided that the following conditions
8*7e321ac1Sguenther  * are met:
9*7e321ac1Sguenther  * 1. Redistributions of source code must retain the above copyright
10*7e321ac1Sguenther  *    notice, this list of conditions and the following disclaimer.
11*7e321ac1Sguenther  * 2. Redistributions in binary form must reproduce the above copyright
12*7e321ac1Sguenther  *    notice, this list of conditions and the following disclaimer in the
13*7e321ac1Sguenther  *    documentation and/or other materials provided with the distribution.
14*7e321ac1Sguenther  *
15*7e321ac1Sguenther  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16*7e321ac1Sguenther  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17*7e321ac1Sguenther  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18*7e321ac1Sguenther  * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
19*7e321ac1Sguenther  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20*7e321ac1Sguenther  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21*7e321ac1Sguenther  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22*7e321ac1Sguenther  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
23*7e321ac1Sguenther  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
24*7e321ac1Sguenther  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25*7e321ac1Sguenther  * POSSIBILITY OF SUCH DAMAGE.
26*7e321ac1Sguenther  */
27*7e321ac1Sguenther 
28*7e321ac1Sguenther /*
29*7e321ac1Sguenther  * Atomic lock for m88k
30*7e321ac1Sguenther  */
31*7e321ac1Sguenther 
32*7e321ac1Sguenther #include <machine/spinlock.h>
33*7e321ac1Sguenther 
34*7e321ac1Sguenther int
_atomic_lock(volatile _atomic_lock_t * lock)35*7e321ac1Sguenther _atomic_lock(volatile _atomic_lock_t *lock)
36*7e321ac1Sguenther {
37*7e321ac1Sguenther 	_atomic_lock_t old;
38*7e321ac1Sguenther 
39*7e321ac1Sguenther 	old = _ATOMIC_LOCK_LOCKED;
40*7e321ac1Sguenther 	__asm__ volatile
41*7e321ac1Sguenther 	    ("xmem %0, %2, %%r0" : "=r" (old) : "0" (old), "r" (lock));
42*7e321ac1Sguenther 
43*7e321ac1Sguenther 	return (old != _ATOMIC_LOCK_UNLOCKED);
44*7e321ac1Sguenther }
45