atomic_ops.h revision 129206
1129206Scognet/*-
2129206Scognet * Copyright (c) 2001 Daniel Eischen <deischen@FreeBSD.org>
3129206Scognet * All rights reserved.
4129206Scognet *
5129206Scognet * Redistribution and use in source and binary forms, with or without
6129206Scognet * modification, are permitted provided that the following conditions
7129206Scognet * are met:
8129206Scognet * 1. Redistributions of source code must retain the above copyright
9129206Scognet *    notice, this list of conditions and the following disclaimer.
10129206Scognet * 2. Neither the name of the author nor the names of its contributors
11129206Scognet *    may be used to endorse or promote products derived from this software
12129206Scognet *    without specific prior written permission.
13129206Scognet *
14129206Scognet * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15129206Scognet * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16129206Scognet * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17129206Scognet * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18129206Scognet * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19129206Scognet * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20129206Scognet * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21129206Scognet * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22129206Scognet * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23129206Scognet * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24129206Scognet * SUCH DAMAGE.
25129206Scognet *
26129206Scognet * $FreeBSD: head/lib/libkse/arch/arm/include/atomic_ops.h 129206 2004-05-14 12:21:29Z cognet $
27129206Scognet */
28129206Scognet
29129206Scognet#ifndef	_ATOMIC_OPS_H_
30129206Scognet#define	_ATOMIC_OPS_H_
31129206Scognet
32129206Scognet/*
33129206Scognet * Atomic swap:
34129206Scognet *   Atomic (tmp = *dst, *dst = val), then *res = tmp
35129206Scognet *
36129206Scognet * void atomic_swap32(intptr_t *dst, intptr_t val, intptr_t *res);
37129206Scognet */
38129206Scognetstatic inline void
39129206Scognetatomic_swap32(intptr_t *dst, intptr_t val, intptr_t *res)
40129206Scognet{
41129206Scognet	__asm __volatile(
42129206Scognet	"swp %2, %2, [%1]; mov %2, %0"
43129206Scognet	 : "=r" (*res) : "r" (dst), "r" (val) : "cc");
44129206Scognet}
45129206Scognet
46129206Scognet#define	atomic_swap_ptr(d, v, r) \
47129206Scognet	atomic_swap32((intptr_t *)d, (intptr_t)v, (intptr_t *)r)
48129206Scognet
49129206Scognet#define	atomic_swap_int(d, v, r) \
50129206Scognet	atomic_swap32((intptr_t *)d, (intptr_t)v, (intptr_t *)r)
51129206Scognet#endif
52