xref: /netbsd-src/sys/external/bsd/common/include/linux/compiler.h (revision 71ee315f14c843fa7ddc43f6fec45971312b4de7)
1*71ee315fSriastradh /*	$NetBSD: compiler.h,v 1.2 2021/12/19 00:48:23 riastradh Exp $	*/
2704dac09Sriastradh 
3704dac09Sriastradh /*-
4704dac09Sriastradh  * Copyright (c) 2018 The NetBSD Foundation, Inc.
5704dac09Sriastradh  * All rights reserved.
6704dac09Sriastradh  *
7704dac09Sriastradh  * This code is derived from software contributed to The NetBSD Foundation
8704dac09Sriastradh  * by Taylor R. Campbell.
9704dac09Sriastradh  *
10704dac09Sriastradh  * Redistribution and use in source and binary forms, with or without
11704dac09Sriastradh  * modification, are permitted provided that the following conditions
12704dac09Sriastradh  * are met:
13704dac09Sriastradh  * 1. Redistributions of source code must retain the above copyright
14704dac09Sriastradh  *    notice, this list of conditions and the following disclaimer.
15704dac09Sriastradh  * 2. Redistributions in binary form must reproduce the above copyright
16704dac09Sriastradh  *    notice, this list of conditions and the following disclaimer in the
17704dac09Sriastradh  *    documentation and/or other materials provided with the distribution.
18704dac09Sriastradh  *
19704dac09Sriastradh  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20704dac09Sriastradh  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21704dac09Sriastradh  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22704dac09Sriastradh  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23704dac09Sriastradh  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24704dac09Sriastradh  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25704dac09Sriastradh  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26704dac09Sriastradh  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27704dac09Sriastradh  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28704dac09Sriastradh  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29704dac09Sriastradh  * POSSIBILITY OF SUCH DAMAGE.
30704dac09Sriastradh  */
31704dac09Sriastradh 
32704dac09Sriastradh #ifndef	_LINUX_COMPILER_H_
33704dac09Sriastradh #define	_LINUX_COMPILER_H_
34704dac09Sriastradh 
35*71ee315fSriastradh #include <sys/atomic.h>
36*71ee315fSriastradh 
37*71ee315fSriastradh #define	READ_ONCE(X)	({						      \
38*71ee315fSriastradh 	typeof(X) __read_once_tmp = (X);				      \
39*71ee315fSriastradh 	membar_datadep_consumer();					      \
40*71ee315fSriastradh 	__read_once_tmp;						      \
41*71ee315fSriastradh })
42*71ee315fSriastradh 
43*71ee315fSriastradh #define	WRITE_ONCE(X, V)	({					      \
44*71ee315fSriastradh 	typeof(X) __write_once_tmp = (V);				      \
45*71ee315fSriastradh 	(X) = __write_once_tmp;						      \
46*71ee315fSriastradh 	__write_once_tmp;						      \
47*71ee315fSriastradh })
48*71ee315fSriastradh 
49704dac09Sriastradh #endif	/* _LINUX_COMPILER_H_ */
50