atomic.h revision 38517
138517Sdfr/*-
238517Sdfr * Copyright (c) 1998 Doug Rabson
338517Sdfr * All rights reserved.
438517Sdfr *
538517Sdfr * Redistribution and use in source and binary forms, with or without
638517Sdfr * modification, are permitted provided that the following conditions
738517Sdfr * are met:
838517Sdfr * 1. Redistributions of source code must retain the above copyright
938517Sdfr *    notice, this list of conditions and the following disclaimer.
1038517Sdfr * 2. Redistributions in binary form must reproduce the above copyright
1138517Sdfr *    notice, this list of conditions and the following disclaimer in the
1238517Sdfr *    documentation and/or other materials provided with the distribution.
1338517Sdfr *
1438517Sdfr * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1538517Sdfr * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1638517Sdfr * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1738517Sdfr * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
1838517Sdfr * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1938517Sdfr * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2038517Sdfr * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2138517Sdfr * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2238517Sdfr * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2338517Sdfr * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2438517Sdfr * SUCH DAMAGE.
2538517Sdfr *
2638517Sdfr *	$Id$
2738517Sdfr */
2838517Sdfr#ifndef _MACHINE_ATOMIC_H_
2938517Sdfr#define _MACHINE_ATOMIC_H_
3038517Sdfr
3138517Sdfr/*
3238517Sdfr * Various simple arithmetic on memory which is atomic in the presence
3338517Sdfr * of interrupts.
3438517Sdfr *
3538517Sdfr * Note: these versions are not SMP safe.
3638517Sdfr */
3738517Sdfr
3838517Sdfr#define atomic_set_char(P, V)		(*(u_char*)(P) |= (V))
3938517Sdfr#define atomic_clear_char(P, V)		(*(u_char*)(P) &= ~(V))
4038517Sdfr#define atomic_add_char(P, V)		(*(u_char*)(P) += (V))
4138517Sdfr#define atomic_subtract_char(P, V)	(*(u_char*)(P) -= (V))
4238517Sdfr
4338517Sdfr#define atomic_set_short(P, V)		(*(u_short*)(P) |= (V))
4438517Sdfr#define atomic_clear_short(P, V)	(*(u_short*)(P) &= ~(V))
4538517Sdfr#define atomic_add_short(P, V)		(*(u_short*)(P) += (V))
4638517Sdfr#define atomic_subtract_short(P, V)	(*(u_short*)(P) -= (V))
4738517Sdfr
4838517Sdfr#define atomic_set_int(P, V)		(*(u_int*)(P) |= (V))
4938517Sdfr#define atomic_clear_int(P, V)		(*(u_int*)(P) &= ~(V))
5038517Sdfr#define atomic_add_int(P, V)		(*(u_int*)(P) += (V))
5138517Sdfr#define atomic_subtract_int(P, V)	(*(u_int*)(P) -= (V))
5238517Sdfr
5338517Sdfr#define atomic_set_long(P, V)		(*(u_long*)(P) |= (V))
5438517Sdfr#define atomic_clear_long(P, V)		(*(u_long*)(P) &= ~(V))
5538517Sdfr#define atomic_add_long(P, V)		(*(u_long*)(P) += (V))
5638517Sdfr#define atomic_subtract_long(P, V)	(*(u_long*)(P) -= (V))
5738517Sdfr
5838517Sdfr#endif /* ! _MACHINE_ATOMIC_H_ */
59