xref: /titanic_52/usr/src/uts/common/sys/atomic.h (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate  * with the License.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate  * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate  *
14*7c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate  *
20*7c478bd9Sstevel@tonic-gate  * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate  */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24*7c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
25*7c478bd9Sstevel@tonic-gate  */
26*7c478bd9Sstevel@tonic-gate 
27*7c478bd9Sstevel@tonic-gate #ifndef	_SYS_ATOMIC_H
28*7c478bd9Sstevel@tonic-gate #define	_SYS_ATOMIC_H
29*7c478bd9Sstevel@tonic-gate 
30*7c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
31*7c478bd9Sstevel@tonic-gate 
32*7c478bd9Sstevel@tonic-gate #include <sys/types.h>
33*7c478bd9Sstevel@tonic-gate #include <sys/inttypes.h>
34*7c478bd9Sstevel@tonic-gate 
35*7c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
36*7c478bd9Sstevel@tonic-gate extern "C" {
37*7c478bd9Sstevel@tonic-gate #endif
38*7c478bd9Sstevel@tonic-gate 
39*7c478bd9Sstevel@tonic-gate #if defined(_KERNEL) && defined(__GNUC__) && defined(_ASM_INLINES)
40*7c478bd9Sstevel@tonic-gate #include <asm/atomic.h>
41*7c478bd9Sstevel@tonic-gate #endif
42*7c478bd9Sstevel@tonic-gate 
43*7c478bd9Sstevel@tonic-gate #if defined(_KERNEL) || defined(__STDC__)
44*7c478bd9Sstevel@tonic-gate /*
45*7c478bd9Sstevel@tonic-gate  * Increment target.
46*7c478bd9Sstevel@tonic-gate  */
47*7c478bd9Sstevel@tonic-gate extern void atomic_inc_8(volatile uint8_t *);
48*7c478bd9Sstevel@tonic-gate extern void atomic_inc_uchar(volatile uchar_t *);
49*7c478bd9Sstevel@tonic-gate extern void atomic_inc_16(volatile uint16_t *);
50*7c478bd9Sstevel@tonic-gate extern void atomic_inc_ushort(volatile ushort_t *);
51*7c478bd9Sstevel@tonic-gate extern void atomic_inc_32(volatile uint32_t *);
52*7c478bd9Sstevel@tonic-gate extern void atomic_inc_uint(volatile uint_t *);
53*7c478bd9Sstevel@tonic-gate extern void atomic_inc_ulong(volatile ulong_t *);
54*7c478bd9Sstevel@tonic-gate #if defined(_KERNEL) || defined(_INT64_TYPE)
55*7c478bd9Sstevel@tonic-gate extern void atomic_inc_64(volatile uint64_t *);
56*7c478bd9Sstevel@tonic-gate #endif
57*7c478bd9Sstevel@tonic-gate 
58*7c478bd9Sstevel@tonic-gate /*
59*7c478bd9Sstevel@tonic-gate  * Decrement target
60*7c478bd9Sstevel@tonic-gate  */
61*7c478bd9Sstevel@tonic-gate extern void atomic_dec_8(volatile uint8_t *);
62*7c478bd9Sstevel@tonic-gate extern void atomic_dec_uchar(volatile uchar_t *);
63*7c478bd9Sstevel@tonic-gate extern void atomic_dec_16(volatile uint16_t *);
64*7c478bd9Sstevel@tonic-gate extern void atomic_dec_ushort(volatile ushort_t *);
65*7c478bd9Sstevel@tonic-gate extern void atomic_dec_32(volatile uint32_t *);
66*7c478bd9Sstevel@tonic-gate extern void atomic_dec_uint(volatile uint_t *);
67*7c478bd9Sstevel@tonic-gate extern void atomic_dec_ulong(volatile ulong_t *);
68*7c478bd9Sstevel@tonic-gate #if defined(_KERNEL) || defined(_INT64_TYPE)
69*7c478bd9Sstevel@tonic-gate extern void atomic_dec_64(volatile uint64_t *);
70*7c478bd9Sstevel@tonic-gate #endif
71*7c478bd9Sstevel@tonic-gate 
72*7c478bd9Sstevel@tonic-gate /*
73*7c478bd9Sstevel@tonic-gate  * Add delta to target
74*7c478bd9Sstevel@tonic-gate  */
75*7c478bd9Sstevel@tonic-gate extern void atomic_add_8(volatile uint8_t *, int8_t);
76*7c478bd9Sstevel@tonic-gate extern void atomic_add_char(volatile uchar_t *, signed char);
77*7c478bd9Sstevel@tonic-gate extern void atomic_add_16(volatile uint16_t *, int16_t);
78*7c478bd9Sstevel@tonic-gate extern void atomic_add_short(volatile ushort_t *, short);
79*7c478bd9Sstevel@tonic-gate extern void atomic_add_32(volatile uint32_t *, int32_t);
80*7c478bd9Sstevel@tonic-gate extern void atomic_add_int(volatile uint_t *, int);
81*7c478bd9Sstevel@tonic-gate extern void atomic_add_ptr(volatile void *, ssize_t);
82*7c478bd9Sstevel@tonic-gate extern void atomic_add_long(volatile ulong_t *, long);
83*7c478bd9Sstevel@tonic-gate #if defined(_KERNEL) || defined(_INT64_TYPE)
84*7c478bd9Sstevel@tonic-gate extern void atomic_add_64(volatile uint64_t *, int64_t);
85*7c478bd9Sstevel@tonic-gate #endif
86*7c478bd9Sstevel@tonic-gate 
87*7c478bd9Sstevel@tonic-gate /*
88*7c478bd9Sstevel@tonic-gate  * logical OR bits with target
89*7c478bd9Sstevel@tonic-gate  */
90*7c478bd9Sstevel@tonic-gate extern void atomic_or_8(volatile uint8_t *, uint8_t);
91*7c478bd9Sstevel@tonic-gate extern void atomic_or_uchar(volatile uchar_t *, uchar_t);
92*7c478bd9Sstevel@tonic-gate extern void atomic_or_16(volatile uint16_t *, uint16_t);
93*7c478bd9Sstevel@tonic-gate extern void atomic_or_ushort(volatile ushort_t *, ushort_t);
94*7c478bd9Sstevel@tonic-gate extern void atomic_or_32(volatile uint32_t *, uint32_t);
95*7c478bd9Sstevel@tonic-gate extern void atomic_or_uint(volatile uint_t *, uint_t);
96*7c478bd9Sstevel@tonic-gate extern void atomic_or_ulong(volatile ulong_t *, ulong_t);
97*7c478bd9Sstevel@tonic-gate #if defined(_KERNEL) || defined(_INT64_TYPE)
98*7c478bd9Sstevel@tonic-gate extern void atomic_or_64(volatile uint64_t *, uint64_t);
99*7c478bd9Sstevel@tonic-gate #endif
100*7c478bd9Sstevel@tonic-gate 
101*7c478bd9Sstevel@tonic-gate /*
102*7c478bd9Sstevel@tonic-gate  * logical AND bits with target
103*7c478bd9Sstevel@tonic-gate  */
104*7c478bd9Sstevel@tonic-gate extern void atomic_and_8(volatile uint8_t *, uint8_t);
105*7c478bd9Sstevel@tonic-gate extern void atomic_and_uchar(volatile uchar_t *, uchar_t);
106*7c478bd9Sstevel@tonic-gate extern void atomic_and_16(volatile uint16_t *, uint16_t);
107*7c478bd9Sstevel@tonic-gate extern void atomic_and_ushort(volatile ushort_t *, ushort_t);
108*7c478bd9Sstevel@tonic-gate extern void atomic_and_32(volatile uint32_t *, uint32_t);
109*7c478bd9Sstevel@tonic-gate extern void atomic_and_uint(volatile uint_t *, uint_t);
110*7c478bd9Sstevel@tonic-gate extern void atomic_and_ulong(volatile ulong_t *, ulong_t);
111*7c478bd9Sstevel@tonic-gate #if defined(_KERNEL) || defined(_INT64_TYPE)
112*7c478bd9Sstevel@tonic-gate extern void atomic_and_64(volatile uint64_t *, uint64_t);
113*7c478bd9Sstevel@tonic-gate #endif
114*7c478bd9Sstevel@tonic-gate 
115*7c478bd9Sstevel@tonic-gate /*
116*7c478bd9Sstevel@tonic-gate  * As above, but return the new value.  Note that these _nv() variants are
117*7c478bd9Sstevel@tonic-gate  * substantially more expensive on some platforms than the no-return-value
118*7c478bd9Sstevel@tonic-gate  * versions above, so don't use them unless you really need to know the
119*7c478bd9Sstevel@tonic-gate  * new value *atomically* (e.g. when decrementing a reference count and
120*7c478bd9Sstevel@tonic-gate  * checking whether it went to zero).
121*7c478bd9Sstevel@tonic-gate  */
122*7c478bd9Sstevel@tonic-gate 
123*7c478bd9Sstevel@tonic-gate /*
124*7c478bd9Sstevel@tonic-gate  * Increment target and return new value.
125*7c478bd9Sstevel@tonic-gate  */
126*7c478bd9Sstevel@tonic-gate extern uint8_t atomic_inc_8_nv(volatile uint8_t *);
127*7c478bd9Sstevel@tonic-gate extern uchar_t atomic_inc_uchar_nv(volatile uchar_t *);
128*7c478bd9Sstevel@tonic-gate extern uint16_t atomic_inc_16_nv(volatile uint16_t *);
129*7c478bd9Sstevel@tonic-gate extern ushort_t atomic_inc_ushort_nv(volatile ushort_t *);
130*7c478bd9Sstevel@tonic-gate extern uint32_t atomic_inc_32_nv(volatile uint32_t *);
131*7c478bd9Sstevel@tonic-gate extern uint_t atomic_inc_uint_nv(volatile uint_t *);
132*7c478bd9Sstevel@tonic-gate extern ulong_t atomic_inc_ulong_nv(volatile ulong_t *);
133*7c478bd9Sstevel@tonic-gate #if defined(_KERNEL) || defined(_INT64_TYPE)
134*7c478bd9Sstevel@tonic-gate extern uint64_t atomic_inc_64_nv(volatile uint64_t *);
135*7c478bd9Sstevel@tonic-gate #endif
136*7c478bd9Sstevel@tonic-gate 
137*7c478bd9Sstevel@tonic-gate /*
138*7c478bd9Sstevel@tonic-gate  * Decrement target and return new value.
139*7c478bd9Sstevel@tonic-gate  */
140*7c478bd9Sstevel@tonic-gate extern uint8_t atomic_dec_8_nv(volatile uint8_t *);
141*7c478bd9Sstevel@tonic-gate extern uchar_t atomic_dec_uchar_nv(volatile uchar_t *);
142*7c478bd9Sstevel@tonic-gate extern uint16_t atomic_dec_16_nv(volatile uint16_t *);
143*7c478bd9Sstevel@tonic-gate extern ushort_t atomic_dec_ushort_nv(volatile ushort_t *);
144*7c478bd9Sstevel@tonic-gate extern uint32_t atomic_dec_32_nv(volatile uint32_t *);
145*7c478bd9Sstevel@tonic-gate extern uint_t atomic_dec_uint_nv(volatile uint_t *);
146*7c478bd9Sstevel@tonic-gate extern ulong_t atomic_dec_ulong_nv(volatile ulong_t *);
147*7c478bd9Sstevel@tonic-gate #if defined(_KERNEL) || defined(_INT64_TYPE)
148*7c478bd9Sstevel@tonic-gate extern uint64_t atomic_dec_64_nv(volatile uint64_t *);
149*7c478bd9Sstevel@tonic-gate #endif
150*7c478bd9Sstevel@tonic-gate 
151*7c478bd9Sstevel@tonic-gate /*
152*7c478bd9Sstevel@tonic-gate  * Add delta to target
153*7c478bd9Sstevel@tonic-gate  */
154*7c478bd9Sstevel@tonic-gate extern uint8_t atomic_add_8_nv(volatile uint8_t *, int8_t);
155*7c478bd9Sstevel@tonic-gate extern uchar_t atomic_add_char_nv(volatile uchar_t *, signed char);
156*7c478bd9Sstevel@tonic-gate extern uint16_t atomic_add_16_nv(volatile uint16_t *, int16_t);
157*7c478bd9Sstevel@tonic-gate extern ushort_t atomic_add_short_nv(volatile ushort_t *, short);
158*7c478bd9Sstevel@tonic-gate extern uint32_t atomic_add_32_nv(volatile uint32_t *, int32_t);
159*7c478bd9Sstevel@tonic-gate extern uint_t atomic_add_int_nv(volatile uint_t *, int);
160*7c478bd9Sstevel@tonic-gate extern void *atomic_add_ptr_nv(volatile void *, ssize_t);
161*7c478bd9Sstevel@tonic-gate extern ulong_t atomic_add_long_nv(volatile ulong_t *, long);
162*7c478bd9Sstevel@tonic-gate #if defined(_KERNEL) || defined(_INT64_TYPE)
163*7c478bd9Sstevel@tonic-gate extern uint64_t atomic_add_64_nv(volatile uint64_t *, int64_t);
164*7c478bd9Sstevel@tonic-gate #endif
165*7c478bd9Sstevel@tonic-gate 
166*7c478bd9Sstevel@tonic-gate /*
167*7c478bd9Sstevel@tonic-gate  * logical OR bits with target and return new value.
168*7c478bd9Sstevel@tonic-gate  */
169*7c478bd9Sstevel@tonic-gate extern uint8_t atomic_or_8_nv(volatile uint8_t *, uint8_t);
170*7c478bd9Sstevel@tonic-gate extern uchar_t atomic_or_uchar_nv(volatile uchar_t *, uchar_t);
171*7c478bd9Sstevel@tonic-gate extern uint16_t atomic_or_16_nv(volatile uint16_t *, uint16_t);
172*7c478bd9Sstevel@tonic-gate extern ushort_t atomic_or_ushort_nv(volatile ushort_t *, ushort_t);
173*7c478bd9Sstevel@tonic-gate extern uint32_t atomic_or_32_nv(volatile uint32_t *, uint32_t);
174*7c478bd9Sstevel@tonic-gate extern uint_t atomic_or_uint_nv(volatile uint_t *, uint_t);
175*7c478bd9Sstevel@tonic-gate extern ulong_t atomic_or_ulong_nv(volatile ulong_t *, ulong_t);
176*7c478bd9Sstevel@tonic-gate #if defined(_KERNEL) || defined(_INT64_TYPE)
177*7c478bd9Sstevel@tonic-gate extern uint64_t atomic_or_64_nv(volatile uint64_t *, uint64_t);
178*7c478bd9Sstevel@tonic-gate #endif
179*7c478bd9Sstevel@tonic-gate 
180*7c478bd9Sstevel@tonic-gate /*
181*7c478bd9Sstevel@tonic-gate  * logical AND bits with target and return new value.
182*7c478bd9Sstevel@tonic-gate  */
183*7c478bd9Sstevel@tonic-gate extern uint8_t atomic_and_8_nv(volatile uint8_t *, uint8_t);
184*7c478bd9Sstevel@tonic-gate extern uchar_t atomic_and_uchar_nv(volatile uchar_t *, uchar_t);
185*7c478bd9Sstevel@tonic-gate extern uint16_t atomic_and_16_nv(volatile uint16_t *, uint16_t);
186*7c478bd9Sstevel@tonic-gate extern ushort_t atomic_and_ushort_nv(volatile ushort_t *, ushort_t);
187*7c478bd9Sstevel@tonic-gate extern uint32_t atomic_and_32_nv(volatile uint32_t *, uint32_t);
188*7c478bd9Sstevel@tonic-gate extern uint_t atomic_and_uint_nv(volatile uint_t *, uint_t);
189*7c478bd9Sstevel@tonic-gate extern ulong_t atomic_and_ulong_nv(volatile ulong_t *, ulong_t);
190*7c478bd9Sstevel@tonic-gate #if defined(_KERNEL) || defined(_INT64_TYPE)
191*7c478bd9Sstevel@tonic-gate extern uint64_t atomic_and_64_nv(volatile uint64_t *, uint64_t);
192*7c478bd9Sstevel@tonic-gate #endif
193*7c478bd9Sstevel@tonic-gate 
194*7c478bd9Sstevel@tonic-gate /*
195*7c478bd9Sstevel@tonic-gate  * If *arg1 == arg2, set *arg1 = arg3; return old value
196*7c478bd9Sstevel@tonic-gate  */
197*7c478bd9Sstevel@tonic-gate extern uint8_t atomic_cas_8(volatile uint8_t *, uint8_t, uint8_t);
198*7c478bd9Sstevel@tonic-gate extern uchar_t atomic_cas_uchar(volatile uchar_t *, uchar_t, uchar_t);
199*7c478bd9Sstevel@tonic-gate extern uint16_t atomic_cas_16(volatile uint16_t *, uint16_t, uint16_t);
200*7c478bd9Sstevel@tonic-gate extern ushort_t atomic_cas_ushort(volatile ushort_t *, ushort_t, ushort_t);
201*7c478bd9Sstevel@tonic-gate extern uint32_t atomic_cas_32(volatile uint32_t *, uint32_t, uint32_t);
202*7c478bd9Sstevel@tonic-gate extern uint_t atomic_cas_uint(volatile uint_t *, uint_t, uint_t);
203*7c478bd9Sstevel@tonic-gate extern void *atomic_cas_ptr(volatile void *, void *, void *);
204*7c478bd9Sstevel@tonic-gate extern ulong_t atomic_cas_ulong(volatile ulong_t *, ulong_t, ulong_t);
205*7c478bd9Sstevel@tonic-gate #if defined(_KERNEL) || defined(_INT64_TYPE)
206*7c478bd9Sstevel@tonic-gate extern uint64_t atomic_cas_64(volatile uint64_t *, uint64_t, uint64_t);
207*7c478bd9Sstevel@tonic-gate #endif
208*7c478bd9Sstevel@tonic-gate 
209*7c478bd9Sstevel@tonic-gate /*
210*7c478bd9Sstevel@tonic-gate  * Swap target and return old value
211*7c478bd9Sstevel@tonic-gate  */
212*7c478bd9Sstevel@tonic-gate extern uint8_t atomic_swap_8(volatile uint8_t *, uint8_t);
213*7c478bd9Sstevel@tonic-gate extern uchar_t atomic_swap_uchar(volatile uchar_t *, uchar_t);
214*7c478bd9Sstevel@tonic-gate extern uint16_t atomic_swap_16(volatile uint16_t *, uint16_t);
215*7c478bd9Sstevel@tonic-gate extern ushort_t atomic_swap_ushort(volatile ushort_t *, ushort_t);
216*7c478bd9Sstevel@tonic-gate extern uint32_t atomic_swap_32(volatile uint32_t *, uint32_t);
217*7c478bd9Sstevel@tonic-gate extern uint_t atomic_swap_uint(volatile uint_t *, uint_t);
218*7c478bd9Sstevel@tonic-gate extern void *atomic_swap_ptr(volatile void *, void *);
219*7c478bd9Sstevel@tonic-gate extern ulong_t atomic_swap_ulong(volatile ulong_t *, ulong_t);
220*7c478bd9Sstevel@tonic-gate #if defined(_KERNEL) || defined(_INT64_TYPE)
221*7c478bd9Sstevel@tonic-gate extern uint64_t atomic_swap_64(volatile uint64_t *, uint64_t);
222*7c478bd9Sstevel@tonic-gate #endif
223*7c478bd9Sstevel@tonic-gate 
224*7c478bd9Sstevel@tonic-gate /*
225*7c478bd9Sstevel@tonic-gate  * Perform an exclusive atomic bit set/clear on a target.
226*7c478bd9Sstevel@tonic-gate  * Returns 0 if bit was sucessfully set/cleared, or -1
227*7c478bd9Sstevel@tonic-gate  * if the bit was already set/cleared.
228*7c478bd9Sstevel@tonic-gate  */
229*7c478bd9Sstevel@tonic-gate extern int atomic_set_long_excl(volatile ulong_t *, uint_t);
230*7c478bd9Sstevel@tonic-gate extern int atomic_clear_long_excl(volatile ulong_t *, uint_t);
231*7c478bd9Sstevel@tonic-gate 
232*7c478bd9Sstevel@tonic-gate /*
233*7c478bd9Sstevel@tonic-gate  * Generic memory barrier used during lock entry, placed after the
234*7c478bd9Sstevel@tonic-gate  * memory operation that acquires the lock to guarantee that the lock
235*7c478bd9Sstevel@tonic-gate  * protects its data.  No stores from after the memory barrier will
236*7c478bd9Sstevel@tonic-gate  * reach visibility, and no loads from after the barrier will be
237*7c478bd9Sstevel@tonic-gate  * resolved, before the lock acquisition reaches global visibility.
238*7c478bd9Sstevel@tonic-gate  */
239*7c478bd9Sstevel@tonic-gate extern void membar_enter(void);
240*7c478bd9Sstevel@tonic-gate 
241*7c478bd9Sstevel@tonic-gate /*
242*7c478bd9Sstevel@tonic-gate  * Generic memory barrier used during lock exit, placed before the
243*7c478bd9Sstevel@tonic-gate  * memory operation that releases the lock to guarantee that the lock
244*7c478bd9Sstevel@tonic-gate  * protects its data.  All loads and stores issued before the barrier
245*7c478bd9Sstevel@tonic-gate  * will be resolved before the subsequent lock update reaches visibility.
246*7c478bd9Sstevel@tonic-gate  */
247*7c478bd9Sstevel@tonic-gate extern void membar_exit(void);
248*7c478bd9Sstevel@tonic-gate 
249*7c478bd9Sstevel@tonic-gate /*
250*7c478bd9Sstevel@tonic-gate  * Arrange that all stores issued before this point in the code reach
251*7c478bd9Sstevel@tonic-gate  * global visibility before any stores that follow; useful in producer
252*7c478bd9Sstevel@tonic-gate  * modules that update a data item, then set a flag that it is available.
253*7c478bd9Sstevel@tonic-gate  * The memory barrier guarantees that the available flag is not visible
254*7c478bd9Sstevel@tonic-gate  * earlier than the updated data, i.e. it imposes store ordering.
255*7c478bd9Sstevel@tonic-gate  */
256*7c478bd9Sstevel@tonic-gate extern void membar_producer(void);
257*7c478bd9Sstevel@tonic-gate 
258*7c478bd9Sstevel@tonic-gate /*
259*7c478bd9Sstevel@tonic-gate  * Arrange that all loads issued before this point in the code are
260*7c478bd9Sstevel@tonic-gate  * completed before any subsequent loads; useful in consumer modules
261*7c478bd9Sstevel@tonic-gate  * that check to see if data is available and read the data.
262*7c478bd9Sstevel@tonic-gate  * The memory barrier guarantees that the data is not sampled until
263*7c478bd9Sstevel@tonic-gate  * after the available flag has been seen, i.e. it imposes load ordering.
264*7c478bd9Sstevel@tonic-gate  */
265*7c478bd9Sstevel@tonic-gate extern void membar_consumer(void);
266*7c478bd9Sstevel@tonic-gate #endif
267*7c478bd9Sstevel@tonic-gate 
268*7c478bd9Sstevel@tonic-gate #if !defined(_KERNEL) && !defined(__STDC__)
269*7c478bd9Sstevel@tonic-gate extern void atomic_inc_8();
270*7c478bd9Sstevel@tonic-gate extern void atomic_inc_uchar();
271*7c478bd9Sstevel@tonic-gate extern void atomic_inc_16();
272*7c478bd9Sstevel@tonic-gate extern void atomic_inc_ushort();
273*7c478bd9Sstevel@tonic-gate extern void atomic_inc_32();
274*7c478bd9Sstevel@tonic-gate extern void atomic_inc_uint();
275*7c478bd9Sstevel@tonic-gate extern void atomic_inc_ulong();
276*7c478bd9Sstevel@tonic-gate #if defined(_INT64_TYPE)
277*7c478bd9Sstevel@tonic-gate extern void atomic_inc_64();
278*7c478bd9Sstevel@tonic-gate #endif /* defined(_INT64_TYPE) */
279*7c478bd9Sstevel@tonic-gate extern void atomic_dec_8();
280*7c478bd9Sstevel@tonic-gate extern void atomic_dec_uchar();
281*7c478bd9Sstevel@tonic-gate extern void atomic_dec_16();
282*7c478bd9Sstevel@tonic-gate extern void atomic_dec_ushort();
283*7c478bd9Sstevel@tonic-gate extern void atomic_dec_32();
284*7c478bd9Sstevel@tonic-gate extern void atomic_dec_uint();
285*7c478bd9Sstevel@tonic-gate extern void atomic_dec_ulong();
286*7c478bd9Sstevel@tonic-gate #if defined(_INT64_TYPE)
287*7c478bd9Sstevel@tonic-gate extern void atomic_dec_64();
288*7c478bd9Sstevel@tonic-gate #endif /* defined(_INT64_TYPE) */
289*7c478bd9Sstevel@tonic-gate extern void atomic_add_8();
290*7c478bd9Sstevel@tonic-gate extern void atomic_add_char();
291*7c478bd9Sstevel@tonic-gate extern void atomic_add_16();
292*7c478bd9Sstevel@tonic-gate extern void atomic_add_short();
293*7c478bd9Sstevel@tonic-gate extern void atomic_add_32();
294*7c478bd9Sstevel@tonic-gate extern void atomic_add_int();
295*7c478bd9Sstevel@tonic-gate extern void atomic_add_ptr();
296*7c478bd9Sstevel@tonic-gate extern void atomic_add_long();
297*7c478bd9Sstevel@tonic-gate #if defined(_INT64_TYPE)
298*7c478bd9Sstevel@tonic-gate extern void atomic_add_64();
299*7c478bd9Sstevel@tonic-gate #endif /* defined(_INT64_TYPE) */
300*7c478bd9Sstevel@tonic-gate extern void atomic_or_8();
301*7c478bd9Sstevel@tonic-gate extern void atomic_or_uchar();
302*7c478bd9Sstevel@tonic-gate extern void atomic_or_16();
303*7c478bd9Sstevel@tonic-gate extern void atomic_or_ushort();
304*7c478bd9Sstevel@tonic-gate extern void atomic_or_32();
305*7c478bd9Sstevel@tonic-gate extern void atomic_or_uint();
306*7c478bd9Sstevel@tonic-gate extern void atomic_or_ulong();
307*7c478bd9Sstevel@tonic-gate #if defined(_INT64_TYPE)
308*7c478bd9Sstevel@tonic-gate extern void atomic_or_64();
309*7c478bd9Sstevel@tonic-gate #endif /* defined(_INT64_TYPE) */
310*7c478bd9Sstevel@tonic-gate extern void atomic_and_8();
311*7c478bd9Sstevel@tonic-gate extern void atomic_and_uchar();
312*7c478bd9Sstevel@tonic-gate extern void atomic_and_16();
313*7c478bd9Sstevel@tonic-gate extern void atomic_and_ushort();
314*7c478bd9Sstevel@tonic-gate extern void atomic_and_32();
315*7c478bd9Sstevel@tonic-gate extern void atomic_and_uint();
316*7c478bd9Sstevel@tonic-gate extern void atomic_and_ulong();
317*7c478bd9Sstevel@tonic-gate #if defined(_INT64_TYPE)
318*7c478bd9Sstevel@tonic-gate extern void atomic_and_64();
319*7c478bd9Sstevel@tonic-gate #endif /* defined(_INT64_TYPE) */
320*7c478bd9Sstevel@tonic-gate extern uint8_t atomic_inc_8_nv();
321*7c478bd9Sstevel@tonic-gate extern uchar_t atomic_inc_uchar_nv();
322*7c478bd9Sstevel@tonic-gate extern uint16_t atomic_inc_16_nv();
323*7c478bd9Sstevel@tonic-gate extern ushort_t atomic_inc_ushort_nv();
324*7c478bd9Sstevel@tonic-gate extern uint32_t atomic_inc_32_nv();
325*7c478bd9Sstevel@tonic-gate extern uint_t atomic_inc_uint_nv();
326*7c478bd9Sstevel@tonic-gate extern ulong_t atomic_inc_ulong_nv();
327*7c478bd9Sstevel@tonic-gate #if defined(_INT64_TYPE)
328*7c478bd9Sstevel@tonic-gate extern uint64_t atomic_inc_64_nv();
329*7c478bd9Sstevel@tonic-gate #endif /* defined(_INT64_TYPE) */
330*7c478bd9Sstevel@tonic-gate extern uint8_t atomic_dec_8_nv();
331*7c478bd9Sstevel@tonic-gate extern uchar_t atomic_dec_uchar_nv();
332*7c478bd9Sstevel@tonic-gate extern uint16_t atomic_dec_16_nv();
333*7c478bd9Sstevel@tonic-gate extern ushort_t atomic_dec_ushort_nv();
334*7c478bd9Sstevel@tonic-gate extern uint32_t atomic_dec_32_nv();
335*7c478bd9Sstevel@tonic-gate extern uint_t atomic_dec_uint_nv();
336*7c478bd9Sstevel@tonic-gate extern ulong_t atomic_dec_ulong_nv();
337*7c478bd9Sstevel@tonic-gate #if defined(_INT64_TYPE)
338*7c478bd9Sstevel@tonic-gate extern uint64_t atomic_dec_64_nv();
339*7c478bd9Sstevel@tonic-gate #endif /* defined(_INT64_TYPE) */
340*7c478bd9Sstevel@tonic-gate extern uint8_t atomic_add_8_nv();
341*7c478bd9Sstevel@tonic-gate extern uchar_t atomic_add_char_nv();
342*7c478bd9Sstevel@tonic-gate extern uint16_t atomic_add_16_nv();
343*7c478bd9Sstevel@tonic-gate extern ushort_t atomic_add_short_nv();
344*7c478bd9Sstevel@tonic-gate extern uint32_t atomic_add_32_nv();
345*7c478bd9Sstevel@tonic-gate extern uint_t atomic_add_int_nv();
346*7c478bd9Sstevel@tonic-gate extern void *atomic_add_ptr_nv();
347*7c478bd9Sstevel@tonic-gate extern ulong_t atomic_add_long_nv();
348*7c478bd9Sstevel@tonic-gate #if defined(_INT64_TYPE)
349*7c478bd9Sstevel@tonic-gate extern uint64_t atomic_add_64_nv();
350*7c478bd9Sstevel@tonic-gate #endif /* defined(_INT64_TYPE) */
351*7c478bd9Sstevel@tonic-gate extern uint8_t atomic_or_8_nv();
352*7c478bd9Sstevel@tonic-gate extern uchar_t atomic_or_uchar_nv();
353*7c478bd9Sstevel@tonic-gate extern uint16_t atomic_or_16_nv();
354*7c478bd9Sstevel@tonic-gate extern ushort_t atomic_or_ushort_nv();
355*7c478bd9Sstevel@tonic-gate extern uint32_t atomic_or_32_nv();
356*7c478bd9Sstevel@tonic-gate extern uint_t atomic_or_uint_nv();
357*7c478bd9Sstevel@tonic-gate extern ulong_t atomic_or_ulong_nv();
358*7c478bd9Sstevel@tonic-gate #if defined(_INT64_TYPE)
359*7c478bd9Sstevel@tonic-gate extern uint64_t atomic_or_64_nv();
360*7c478bd9Sstevel@tonic-gate #endif /* defined(_INT64_TYPE) */
361*7c478bd9Sstevel@tonic-gate extern uint8_t atomic_and_8_nv();
362*7c478bd9Sstevel@tonic-gate extern uchar_t atomic_and_uchar_nv();
363*7c478bd9Sstevel@tonic-gate extern uint16_t atomic_and_16_nv();
364*7c478bd9Sstevel@tonic-gate extern ushort_t atomic_and_ushort_nv();
365*7c478bd9Sstevel@tonic-gate extern uint32_t atomic_and_32_nv();
366*7c478bd9Sstevel@tonic-gate extern uint_t atomic_and_uint_nv();
367*7c478bd9Sstevel@tonic-gate extern ulong_t atomic_and_ulong_nv();
368*7c478bd9Sstevel@tonic-gate #if defined(_INT64_TYPE)
369*7c478bd9Sstevel@tonic-gate extern uint64_t atomic_and_64_nv();
370*7c478bd9Sstevel@tonic-gate #endif /* defined(_INT64_TYPE) */
371*7c478bd9Sstevel@tonic-gate extern uint8_t atomic_cas_8();
372*7c478bd9Sstevel@tonic-gate extern uchar_t atomic_cas_uchar();
373*7c478bd9Sstevel@tonic-gate extern uint16_t atomic_cas_16();
374*7c478bd9Sstevel@tonic-gate extern ushort_t atomic_cas_ushort();
375*7c478bd9Sstevel@tonic-gate extern uint32_t atomic_cas_32();
376*7c478bd9Sstevel@tonic-gate extern uint_t atomic_cas_uint();
377*7c478bd9Sstevel@tonic-gate extern void *atomic_cas_ptr();
378*7c478bd9Sstevel@tonic-gate extern ulong_t atomic_cas_ulong();
379*7c478bd9Sstevel@tonic-gate #if defined(_INT64_TYPE)
380*7c478bd9Sstevel@tonic-gate extern uint64_t atomic_cas_64();
381*7c478bd9Sstevel@tonic-gate #endif /* defined(_INT64_TYPE) */
382*7c478bd9Sstevel@tonic-gate extern uint8_t atomic_swap_8();
383*7c478bd9Sstevel@tonic-gate extern uchar_t atomic_swap_uchar();
384*7c478bd9Sstevel@tonic-gate extern uint16_t atomic_swap_16();
385*7c478bd9Sstevel@tonic-gate extern ushort_t atomic_swap_ushort();
386*7c478bd9Sstevel@tonic-gate extern uint32_t atomic_swap_32();
387*7c478bd9Sstevel@tonic-gate extern uint_t atomic_swap_uint();
388*7c478bd9Sstevel@tonic-gate extern void *atomic_swap_ptr();
389*7c478bd9Sstevel@tonic-gate extern ulong_t atomic_swap_ulong();
390*7c478bd9Sstevel@tonic-gate #if defined(_INT64_TYPE)
391*7c478bd9Sstevel@tonic-gate extern uint64_t atomic_swap_64();
392*7c478bd9Sstevel@tonic-gate #endif /* defined(_INT64_TYPE) */
393*7c478bd9Sstevel@tonic-gate 
394*7c478bd9Sstevel@tonic-gate 
395*7c478bd9Sstevel@tonic-gate extern int atomic_set_long_excl();
396*7c478bd9Sstevel@tonic-gate extern int atomic_clear_long_excl();
397*7c478bd9Sstevel@tonic-gate 
398*7c478bd9Sstevel@tonic-gate extern void membar_enter();
399*7c478bd9Sstevel@tonic-gate extern void membar_exit();
400*7c478bd9Sstevel@tonic-gate extern void membar_producer();
401*7c478bd9Sstevel@tonic-gate extern void membar_consumer();
402*7c478bd9Sstevel@tonic-gate 
403*7c478bd9Sstevel@tonic-gate #endif
404*7c478bd9Sstevel@tonic-gate 
405*7c478bd9Sstevel@tonic-gate #if defined(_KERNEL)
406*7c478bd9Sstevel@tonic-gate 
407*7c478bd9Sstevel@tonic-gate #if defined(_LP64) || defined(_ILP32)
408*7c478bd9Sstevel@tonic-gate #define	atomic_add_ip		atomic_add_long
409*7c478bd9Sstevel@tonic-gate #define	atomic_add_ip_nv	atomic_add_long_nv
410*7c478bd9Sstevel@tonic-gate #define	casip			atomic_cas_ulong
411*7c478bd9Sstevel@tonic-gate #endif
412*7c478bd9Sstevel@tonic-gate 
413*7c478bd9Sstevel@tonic-gate #if defined(__sparc)
414*7c478bd9Sstevel@tonic-gate extern uint8_t ldstub(uint8_t *);
415*7c478bd9Sstevel@tonic-gate #endif
416*7c478bd9Sstevel@tonic-gate 
417*7c478bd9Sstevel@tonic-gate /*
418*7c478bd9Sstevel@tonic-gate  * Legacy kernel interfaces; they will go away (eventually).
419*7c478bd9Sstevel@tonic-gate  */
420*7c478bd9Sstevel@tonic-gate extern uint8_t cas8(uint8_t *, uint8_t, uint8_t);
421*7c478bd9Sstevel@tonic-gate extern uint32_t cas32(uint32_t *, uint32_t, uint32_t);
422*7c478bd9Sstevel@tonic-gate extern uint64_t cas64(uint64_t *, uint64_t, uint64_t);
423*7c478bd9Sstevel@tonic-gate extern ulong_t caslong(ulong_t *, ulong_t, ulong_t);
424*7c478bd9Sstevel@tonic-gate extern void *casptr(void *, void *, void *);
425*7c478bd9Sstevel@tonic-gate extern void atomic_and_long(ulong_t *, ulong_t);
426*7c478bd9Sstevel@tonic-gate extern void atomic_or_long(ulong_t *, ulong_t);
427*7c478bd9Sstevel@tonic-gate #if defined(__sparc)
428*7c478bd9Sstevel@tonic-gate extern uint32_t swapl(uint32_t *, uint32_t);
429*7c478bd9Sstevel@tonic-gate #endif
430*7c478bd9Sstevel@tonic-gate 
431*7c478bd9Sstevel@tonic-gate #endif	/* _KERNEL */
432*7c478bd9Sstevel@tonic-gate 
433*7c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
434*7c478bd9Sstevel@tonic-gate }
435*7c478bd9Sstevel@tonic-gate #endif
436*7c478bd9Sstevel@tonic-gate 
437*7c478bd9Sstevel@tonic-gate #endif	/* _SYS_ATOMIC_H */
438