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$
27129206Scognet */
28129206Scognet
29129206Scognet#ifndef	_ATOMIC_OPS_H_
30129206Scognet#define	_ATOMIC_OPS_H_
31129206Scognet
32137283Scognet#include <machine/atomic.h>
33137283Scognet#include "thr_private.h"
34137283Scognet
35129206Scognet/*
36129206Scognet * Atomic swap:
37129206Scognet *   Atomic (tmp = *dst, *dst = val), then *res = tmp
38129206Scognet *
39129206Scognet * void atomic_swap32(intptr_t *dst, intptr_t val, intptr_t *res);
40129206Scognet */
41129206Scognetstatic inline void
42174112Sdeischenatomic_swap32(volatile intptr_t *dst, intptr_t val, intptr_t *res)
43129206Scognet{
44137283Scognet	*res = __swp(val, dst);
45129206Scognet}
46129206Scognet
47129206Scognet#define	atomic_swap_ptr(d, v, r) \
48174112Sdeischen	atomic_swap32((volatile intptr_t *)d, (intptr_t)v, (intptr_t *)r)
49129206Scognet
50129206Scognet#define	atomic_swap_int(d, v, r) \
51174112Sdeischen	atomic_swap32((volatile intptr_t *)d, (intptr_t)v, (intptr_t *)r)
52129206Scognet#endif
53137283Scognet
54