1116707Smarcel/* 2116707Smarcel * Copyright (c) 2003 Marcel Moolenaar 3116707Smarcel * All rights reserved. 4116707Smarcel * 5116707Smarcel * Redistribution and use in source and binary forms, with or without 6116707Smarcel * modification, are permitted provided that the following conditions 7116707Smarcel * are met: 8116707Smarcel * 9116707Smarcel * 1. Redistributions of source code must retain the above copyright 10116707Smarcel * notice, this list of conditions and the following disclaimer. 11116707Smarcel * 2. Redistributions in binary form must reproduce the above copyright 12116707Smarcel * notice, this list of conditions and the following disclaimer in the 13116707Smarcel * documentation and/or other materials provided with the distribution. 14116707Smarcel * 15116707Smarcel * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 16116707Smarcel * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17116707Smarcel * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18116707Smarcel * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 19116707Smarcel * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20116707Smarcel * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21116707Smarcel * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22116707Smarcel * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23116707Smarcel * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24116707Smarcel * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25116707Smarcel * 26116707Smarcel * $FreeBSD$ 27116707Smarcel */ 28116707Smarcel 29116707Smarcel#ifndef _ATOMIC_OPS_H_ 30116707Smarcel#define _ATOMIC_OPS_H_ 31116707Smarcel 32116707Smarcelstatic inline void 33174112Sdeischenatomic_swap_int(volatile int *dst, int val, int *res) 34116707Smarcel{ 35116707Smarcel __asm("xchg4 %0=[%2],%1" : "=r"(*res) : "r"(val), "r"(dst)); 36116707Smarcel} 37116707Smarcel 38116707Smarcelstatic inline void 39174112Sdeischenatomic_swap_long(volatile long *dst, long val, long *res) 40116707Smarcel{ 41116707Smarcel __asm("xchg8 %0=[%2],%1" : "=r"(*res) : "r"(val), "r"(dst)); 42116707Smarcel} 43116707Smarcel 44116707Smarcel#define atomic_swap_ptr(d,v,r) \ 45174112Sdeischen atomic_swap_long((volatile long *)d, (long)v, (long *)r) 46116707Smarcel 47116707Smarcel#endif /* _ATOMIC_OPS_H_ */ 48