1228919Sed/*- 2228919Sed * Copyright (c) 2011 Ed Schouten <ed@FreeBSD.org> 3228919Sed * All rights reserved. 4228919Sed * 5228919Sed * Redistribution and use in source and binary forms, with or without 6228919Sed * modification, are permitted provided that the following conditions 7228919Sed * are met: 8228919Sed * 1. Redistributions of source code must retain the above copyright 9228919Sed * notice, this list of conditions and the following disclaimer. 10228919Sed * 2. Redistributions in binary form must reproduce the above copyright 11228919Sed * notice, this list of conditions and the following disclaimer in the 12228919Sed * documentation and/or other materials provided with the distribution. 13228919Sed * 14228919Sed * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15228919Sed * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16228919Sed * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17228919Sed * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18228919Sed * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19228919Sed * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20228919Sed * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21228919Sed * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22228919Sed * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23228919Sed * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24228919Sed * SUCH DAMAGE. 25228919Sed */ 26228919Sed 27228919Sed#include <sys/cdefs.h> 28228919Sed__FBSDID("$FreeBSD$"); 29228919Sed 30228919Sed#include <sys/types.h> 31228919Sed#include <machine/atomic.h> 32228919Sed 33228919SedTYPE 34228919SedNAME(volatile TYPE *ptr, TYPE value) 35228919Sed{ 36228919Sed TYPE t; 37228919Sed 38228919Sed#ifdef FETCHADD 39228919Sed t = FETCHADD(ptr, value); 40228919Sed#else 41228919Sed do { 42228919Sed t = *ptr; 43228919Sed } while (!CMPSET(ptr, t, EXPRESSION)); 44228919Sed#endif 45228919Sed 46228919Sed return (t); 47228919Sed} 48