1 /*- 2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD 3 * 4 * Copyright (c) 2017 The FreeBSD Foundation 5 * All rights reserved. 6 * 7 * This software was developed by Konstantin Belousov <kib@FreeBSD.org> 8 * under sponsorship from the FreeBSD Foundation. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29 * SUCH DAMAGE. 30 * 31 * $FreeBSD$ 32 */ 33 #ifndef _SYS_ATOMIC_COMMON_H_ 34 #define _SYS_ATOMIC_COMMON_H_ 35 36 #ifndef _MACHINE_ATOMIC_H_ 37 #error do not include this header, use machine/atomic.h 38 #endif 39 40 #define atomic_load_char(p) (*(volatile u_char *)(p)) 41 #define atomic_load_short(p) (*(volatile u_short *)(p)) 42 #define atomic_load_int(p) (*(volatile u_int *)(p)) 43 #define atomic_load_long(p) (*(volatile u_long *)(p)) 44 #define atomic_load_ptr(p) (*(volatile __typeof(p))(p)) 45 #define atomic_load_8(p) (*(volatile uint8_t *)(p)) 46 #define atomic_load_16(p) (*(volatile uint16_t *)(p)) 47 #define atomic_load_32(p) (*(volatile uint32_t *)(p)) 48 #ifdef _LP64 49 #define atomic_load_64(p) (*(volatile uint64_t *)(p)) 50 #endif 51 52 #define atomic_store_char(p, v) \ 53 (*(volatile u_char *)(p) = (u_char)(v)) 54 #define atomic_store_short(p, v) \ 55 (*(volatile u_short *)(p) = (u_short)(v)) 56 #define atomic_store_int(p, v) \ 57 (*(volatile u_int *)(p) = (u_int)(v)) 58 #define atomic_store_long(p, v) \ 59 (*(volatile u_long *)(p) = (u_long)(v)) 60 #define atomic_store_ptr(p, v) \ 61 (*(volatile uintptr_t *)(p) = (uintptr_t)(v)) 62 #define atomic_store_8(p, v) \ 63 (*(volatile uint8_t *)(p) = (uint8_t)(v)) 64 #define atomic_store_16(p, v) \ 65 (*(volatile uint16_t *)(p) = (uint16_t)(v)) 66 #define atomic_store_32(p, v) \ 67 (*(volatile uint32_t *)(p) = (uint32_t)(v)) 68 #ifdef _LP64 69 #define atomic_store_64(p, v) \ 70 (*(volatile uint64_t *)(p) = (uint64_t)(v)) 71 #endif 72 73 #endif 74