1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate  * CDDL HEADER START
3*0Sstevel@tonic-gate  *
4*0Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*0Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*0Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*0Sstevel@tonic-gate  * with the License.
8*0Sstevel@tonic-gate  *
9*0Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*0Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*0Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*0Sstevel@tonic-gate  * and limitations under the License.
13*0Sstevel@tonic-gate  *
14*0Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*0Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*0Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*0Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*0Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*0Sstevel@tonic-gate  *
20*0Sstevel@tonic-gate  * CDDL HEADER END
21*0Sstevel@tonic-gate  */
22*0Sstevel@tonic-gate /*
23*0Sstevel@tonic-gate  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24*0Sstevel@tonic-gate  * Use is subject to license terms.
25*0Sstevel@tonic-gate  */
26*0Sstevel@tonic-gate 
27*0Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
28*0Sstevel@tonic-gate 
29*0Sstevel@tonic-gate #include <sys/atomic.h>
30*0Sstevel@tonic-gate 
31*0Sstevel@tonic-gate /*
32*0Sstevel@tonic-gate  * This file exists only for the purpose of running lint.
33*0Sstevel@tonic-gate  */
34*0Sstevel@tonic-gate 
35*0Sstevel@tonic-gate #if defined(__lint)
36*0Sstevel@tonic-gate 
37*0Sstevel@tonic-gate void
38*0Sstevel@tonic-gate atomic_inc_8(volatile uint8_t *target)
39*0Sstevel@tonic-gate { (*target)++; }
40*0Sstevel@tonic-gate 
41*0Sstevel@tonic-gate void
42*0Sstevel@tonic-gate atomic_inc_uchar(volatile uchar_t *target)
43*0Sstevel@tonic-gate { (*target)++; }
44*0Sstevel@tonic-gate 
45*0Sstevel@tonic-gate void
46*0Sstevel@tonic-gate atomic_inc_16(volatile uint16_t *target)
47*0Sstevel@tonic-gate { (*target)++; }
48*0Sstevel@tonic-gate 
49*0Sstevel@tonic-gate void
50*0Sstevel@tonic-gate atomic_inc_ushort(volatile ushort_t *target)
51*0Sstevel@tonic-gate { (*target)++; }
52*0Sstevel@tonic-gate 
53*0Sstevel@tonic-gate void
54*0Sstevel@tonic-gate atomic_inc_32(volatile uint32_t *target)
55*0Sstevel@tonic-gate { (*target)++; }
56*0Sstevel@tonic-gate 
57*0Sstevel@tonic-gate void
58*0Sstevel@tonic-gate atomic_inc_uint(volatile uint_t *target)
59*0Sstevel@tonic-gate { (*target)++; }
60*0Sstevel@tonic-gate 
61*0Sstevel@tonic-gate void
62*0Sstevel@tonic-gate atomic_inc_ulong(volatile ulong_t *target)
63*0Sstevel@tonic-gate { (*target)++; }
64*0Sstevel@tonic-gate 
65*0Sstevel@tonic-gate void
66*0Sstevel@tonic-gate atomic_inc_64(volatile uint64_t *target)
67*0Sstevel@tonic-gate { (*target)++; }
68*0Sstevel@tonic-gate 
69*0Sstevel@tonic-gate void
70*0Sstevel@tonic-gate atomic_dec_8(volatile uint8_t *target)
71*0Sstevel@tonic-gate { (*target)--; }
72*0Sstevel@tonic-gate 
73*0Sstevel@tonic-gate void
74*0Sstevel@tonic-gate atomic_dec_uchar(volatile uchar_t *target)
75*0Sstevel@tonic-gate { (*target)--; }
76*0Sstevel@tonic-gate 
77*0Sstevel@tonic-gate void
78*0Sstevel@tonic-gate atomic_dec_16(volatile uint16_t *target)
79*0Sstevel@tonic-gate { (*target)--; }
80*0Sstevel@tonic-gate 
81*0Sstevel@tonic-gate void
82*0Sstevel@tonic-gate atomic_dec_ushort(volatile ushort_t *target)
83*0Sstevel@tonic-gate { (*target)--; }
84*0Sstevel@tonic-gate 
85*0Sstevel@tonic-gate void
86*0Sstevel@tonic-gate atomic_dec_32(volatile uint32_t *target)
87*0Sstevel@tonic-gate { (*target)--; }
88*0Sstevel@tonic-gate 
89*0Sstevel@tonic-gate void
90*0Sstevel@tonic-gate atomic_dec_uint(volatile uint_t *target)
91*0Sstevel@tonic-gate { (*target)--; }
92*0Sstevel@tonic-gate 
93*0Sstevel@tonic-gate void
94*0Sstevel@tonic-gate atomic_dec_ulong(volatile ulong_t *target)
95*0Sstevel@tonic-gate { (*target)--; }
96*0Sstevel@tonic-gate 
97*0Sstevel@tonic-gate void
98*0Sstevel@tonic-gate atomic_dec_64(volatile uint64_t *target)
99*0Sstevel@tonic-gate { (*target)--; }
100*0Sstevel@tonic-gate 
101*0Sstevel@tonic-gate void
102*0Sstevel@tonic-gate atomic_add_8(volatile uint8_t *target, int8_t value)
103*0Sstevel@tonic-gate { *target += value; }
104*0Sstevel@tonic-gate 
105*0Sstevel@tonic-gate void
106*0Sstevel@tonic-gate atomic_add_char(volatile uchar_t *target, signed char value)
107*0Sstevel@tonic-gate { *target += value; }
108*0Sstevel@tonic-gate 
109*0Sstevel@tonic-gate void
110*0Sstevel@tonic-gate atomic_add_16(volatile uint16_t *target, int16_t delta)
111*0Sstevel@tonic-gate { *target += delta; }
112*0Sstevel@tonic-gate 
113*0Sstevel@tonic-gate void
114*0Sstevel@tonic-gate atomic_add_ushort(volatile ushort_t *target, short value)
115*0Sstevel@tonic-gate { *target += value; }
116*0Sstevel@tonic-gate 
117*0Sstevel@tonic-gate void
118*0Sstevel@tonic-gate atomic_add_32(volatile uint32_t *target, int32_t delta)
119*0Sstevel@tonic-gate { *target += delta; }
120*0Sstevel@tonic-gate 
121*0Sstevel@tonic-gate void
122*0Sstevel@tonic-gate atomic_add_ptr(volatile void *target, ssize_t value)
123*0Sstevel@tonic-gate { *(caddr_t *)target += value; }
124*0Sstevel@tonic-gate 
125*0Sstevel@tonic-gate void
126*0Sstevel@tonic-gate atomic_add_long(volatile ulong_t *target, long delta)
127*0Sstevel@tonic-gate { *target += delta; }
128*0Sstevel@tonic-gate 
129*0Sstevel@tonic-gate void
130*0Sstevel@tonic-gate atomic_add_64(volatile uint64_t *target, int64_t delta)
131*0Sstevel@tonic-gate { *target += delta; }
132*0Sstevel@tonic-gate 
133*0Sstevel@tonic-gate void
134*0Sstevel@tonic-gate atomic_or_8(volatile uint8_t *target, uint8_t bits)
135*0Sstevel@tonic-gate { *target |= bits; }
136*0Sstevel@tonic-gate 
137*0Sstevel@tonic-gate void
138*0Sstevel@tonic-gate atomic_or_uchar(volatile uchar_t *target, uchar_t bits)
139*0Sstevel@tonic-gate { *target |= bits; }
140*0Sstevel@tonic-gate 
141*0Sstevel@tonic-gate void
142*0Sstevel@tonic-gate atomic_or_16(volatile uint16_t *target, uint16_t bits)
143*0Sstevel@tonic-gate { *target |= bits; }
144*0Sstevel@tonic-gate 
145*0Sstevel@tonic-gate void
146*0Sstevel@tonic-gate atomic_or_ushort(volatile ushort_t *target, ushort_t bits)
147*0Sstevel@tonic-gate { *target |= bits; }
148*0Sstevel@tonic-gate 
149*0Sstevel@tonic-gate void
150*0Sstevel@tonic-gate atomic_or_32(volatile uint32_t *target, uint32_t bits)
151*0Sstevel@tonic-gate { *target |= bits; }
152*0Sstevel@tonic-gate 
153*0Sstevel@tonic-gate void
154*0Sstevel@tonic-gate atomic_or_uint(volatile uint_t *target, uint_t bits)
155*0Sstevel@tonic-gate { *target |= bits; }
156*0Sstevel@tonic-gate 
157*0Sstevel@tonic-gate void
158*0Sstevel@tonic-gate atomic_or_ulong(volatile ulong_t *target, ulong_t bits)
159*0Sstevel@tonic-gate { *target |= bits; }
160*0Sstevel@tonic-gate 
161*0Sstevel@tonic-gate void
162*0Sstevel@tonic-gate atomic_or_64(volatile uint64_t *target, uint64_t bits)
163*0Sstevel@tonic-gate { *target |= bits; }
164*0Sstevel@tonic-gate 
165*0Sstevel@tonic-gate void
166*0Sstevel@tonic-gate atomic_and_8(volatile uint8_t *target, uint8_t bits)
167*0Sstevel@tonic-gate { *target &= bits; }
168*0Sstevel@tonic-gate 
169*0Sstevel@tonic-gate void
170*0Sstevel@tonic-gate atomic_and_uchar(volatile uchar_t *target, uchar_t bits)
171*0Sstevel@tonic-gate { *target &= bits; }
172*0Sstevel@tonic-gate 
173*0Sstevel@tonic-gate void
174*0Sstevel@tonic-gate atomic_and_16(volatile uint16_t *target, uint16_t bits)
175*0Sstevel@tonic-gate { *target &= bits; }
176*0Sstevel@tonic-gate 
177*0Sstevel@tonic-gate void
178*0Sstevel@tonic-gate atomic_and_ushort(volatile ushort_t *target, ushort_t bits)
179*0Sstevel@tonic-gate { *target &= bits; }
180*0Sstevel@tonic-gate 
181*0Sstevel@tonic-gate void
182*0Sstevel@tonic-gate atomic_and_32(volatile uint32_t *target, uint32_t bits)
183*0Sstevel@tonic-gate { *target &= bits; }
184*0Sstevel@tonic-gate 
185*0Sstevel@tonic-gate void
186*0Sstevel@tonic-gate atomic_and_uint(volatile uint_t *target, uint_t bits)
187*0Sstevel@tonic-gate { *target &= bits; }
188*0Sstevel@tonic-gate 
189*0Sstevel@tonic-gate void
190*0Sstevel@tonic-gate atomic_and_ulong(volatile ulong_t *target, ulong_t bits)
191*0Sstevel@tonic-gate { *target &= bits; }
192*0Sstevel@tonic-gate 
193*0Sstevel@tonic-gate void
194*0Sstevel@tonic-gate atomic_and_64(volatile uint64_t *target, uint64_t bits)
195*0Sstevel@tonic-gate { *target &= bits; }
196*0Sstevel@tonic-gate 
197*0Sstevel@tonic-gate uint8_t
198*0Sstevel@tonic-gate atomic_inc_8_nv(volatile uint8_t *target)
199*0Sstevel@tonic-gate { return (++(*target)); }
200*0Sstevel@tonic-gate 
201*0Sstevel@tonic-gate uchar_t
202*0Sstevel@tonic-gate atomic_inc_uchar_nv(volatile uchar_t *target)
203*0Sstevel@tonic-gate { return (++(*target)); }
204*0Sstevel@tonic-gate 
205*0Sstevel@tonic-gate uint16_t
206*0Sstevel@tonic-gate atomic_inc_16_nv(volatile uint16_t *target)
207*0Sstevel@tonic-gate { return (++(*target)); }
208*0Sstevel@tonic-gate 
209*0Sstevel@tonic-gate ushort_t
210*0Sstevel@tonic-gate atomic_inc_ushort_nv(volatile ushort_t *target)
211*0Sstevel@tonic-gate { return (++(*target)); }
212*0Sstevel@tonic-gate 
213*0Sstevel@tonic-gate uint32_t
214*0Sstevel@tonic-gate atomic_inc_32_nv(volatile uint32_t *target)
215*0Sstevel@tonic-gate { return (++(*target)); }
216*0Sstevel@tonic-gate 
217*0Sstevel@tonic-gate uint_t
218*0Sstevel@tonic-gate atomic_inc_uint_nv(volatile uint_t *target)
219*0Sstevel@tonic-gate { return (++(*target)); }
220*0Sstevel@tonic-gate 
221*0Sstevel@tonic-gate ulong_t
222*0Sstevel@tonic-gate atomic_inc_ulong_nv(volatile ulong_t *target)
223*0Sstevel@tonic-gate { return (++(*target)); }
224*0Sstevel@tonic-gate 
225*0Sstevel@tonic-gate uint64_t
226*0Sstevel@tonic-gate atomic_inc_64_nv(volatile uint64_t *target)
227*0Sstevel@tonic-gate { return (++(*target)); }
228*0Sstevel@tonic-gate 
229*0Sstevel@tonic-gate uint8_t
230*0Sstevel@tonic-gate atomic_dec_8_nv(volatile uint8_t *target)
231*0Sstevel@tonic-gate { return (--(*target)); }
232*0Sstevel@tonic-gate 
233*0Sstevel@tonic-gate uchar_t
234*0Sstevel@tonic-gate atomic_dec_uchar_nv(volatile uchar_t *target)
235*0Sstevel@tonic-gate { return (--(*target)); }
236*0Sstevel@tonic-gate 
237*0Sstevel@tonic-gate uint16_t
238*0Sstevel@tonic-gate atomic_dec_16_nv(volatile uint16_t *target)
239*0Sstevel@tonic-gate { return (--(*target)); }
240*0Sstevel@tonic-gate 
241*0Sstevel@tonic-gate ushort_t
242*0Sstevel@tonic-gate atomic_dec_ushort_nv(volatile ushort_t *target)
243*0Sstevel@tonic-gate { return (--(*target)); }
244*0Sstevel@tonic-gate 
245*0Sstevel@tonic-gate uint32_t
246*0Sstevel@tonic-gate atomic_dec_32_nv(volatile uint32_t *target)
247*0Sstevel@tonic-gate { return (--(*target)); }
248*0Sstevel@tonic-gate 
249*0Sstevel@tonic-gate uint_t
250*0Sstevel@tonic-gate atomic_dec_uint_nv(volatile uint_t *target)
251*0Sstevel@tonic-gate { return (--(*target)); }
252*0Sstevel@tonic-gate 
253*0Sstevel@tonic-gate ulong_t
254*0Sstevel@tonic-gate atomic_dec_ulong_nv(volatile ulong_t *target)
255*0Sstevel@tonic-gate { return (--(*target)); }
256*0Sstevel@tonic-gate 
257*0Sstevel@tonic-gate uint64_t
258*0Sstevel@tonic-gate atomic_dec_64_nv(volatile uint64_t *target)
259*0Sstevel@tonic-gate { return (--(*target)); }
260*0Sstevel@tonic-gate 
261*0Sstevel@tonic-gate uint8_t
262*0Sstevel@tonic-gate atomic_add_8_nv(volatile uint8_t *target, int8_t value)
263*0Sstevel@tonic-gate { return (*target += value); }
264*0Sstevel@tonic-gate 
265*0Sstevel@tonic-gate uchar_t
266*0Sstevel@tonic-gate atomic_add_char_nv(volatile uchar_t *target, signed char value)
267*0Sstevel@tonic-gate { return (*target += value); }
268*0Sstevel@tonic-gate 
269*0Sstevel@tonic-gate uint16_t
270*0Sstevel@tonic-gate atomic_add_16_nv(volatile uint16_t *target, int16_t delta)
271*0Sstevel@tonic-gate { return (*target += delta); }
272*0Sstevel@tonic-gate 
273*0Sstevel@tonic-gate ushort_t
274*0Sstevel@tonic-gate atomic_add_short_nv(volatile ushort_t *target, short value)
275*0Sstevel@tonic-gate { return (*target += value); }
276*0Sstevel@tonic-gate 
277*0Sstevel@tonic-gate uint32_t
278*0Sstevel@tonic-gate atomic_add_32_nv(volatile uint32_t *target, int32_t delta)
279*0Sstevel@tonic-gate { return (*target += delta); }
280*0Sstevel@tonic-gate 
281*0Sstevel@tonic-gate uint_t
282*0Sstevel@tonic-gate atomic_add_int_nv(volatile uint_t *target, int delta)
283*0Sstevel@tonic-gate { return (*target += delta); }
284*0Sstevel@tonic-gate 
285*0Sstevel@tonic-gate void *
286*0Sstevel@tonic-gate atomic_add_ptr_nv(volatile void *target, ssize_t value)
287*0Sstevel@tonic-gate { return (*(caddr_t *)target += value); }
288*0Sstevel@tonic-gate 
289*0Sstevel@tonic-gate ulong_t
290*0Sstevel@tonic-gate atomic_add_long_nv(volatile ulong_t *target, long delta)
291*0Sstevel@tonic-gate { return (*target += delta); }
292*0Sstevel@tonic-gate 
293*0Sstevel@tonic-gate uint64_t
294*0Sstevel@tonic-gate atomic_add_64_nv(volatile uint64_t *target, int64_t delta)
295*0Sstevel@tonic-gate { return (*target += delta); }
296*0Sstevel@tonic-gate 
297*0Sstevel@tonic-gate uint8_t
298*0Sstevel@tonic-gate atomic_or_8_nv(volatile uint8_t *target, uint8_t value)
299*0Sstevel@tonic-gate { return (*target |= value); }
300*0Sstevel@tonic-gate 
301*0Sstevel@tonic-gate uchar_t
302*0Sstevel@tonic-gate atomic_or_uchar_nv(volatile uchar_t *target, uchar_t value)
303*0Sstevel@tonic-gate { return (*target |= value); }
304*0Sstevel@tonic-gate 
305*0Sstevel@tonic-gate uint16_t
306*0Sstevel@tonic-gate atomic_or_16_nv(volatile uint16_t *target, uint16_t value)
307*0Sstevel@tonic-gate { return (*target |= value); }
308*0Sstevel@tonic-gate 
309*0Sstevel@tonic-gate ushort_t
310*0Sstevel@tonic-gate atomic_or_ushort_nv(volatile ushort_t *target, ushort_t value)
311*0Sstevel@tonic-gate { return (*target |= value); }
312*0Sstevel@tonic-gate 
313*0Sstevel@tonic-gate uint32_t
314*0Sstevel@tonic-gate atomic_or_32_nv(volatile uint32_t *target, uint32_t value)
315*0Sstevel@tonic-gate { return (*target |= value); }
316*0Sstevel@tonic-gate 
317*0Sstevel@tonic-gate uint_t
318*0Sstevel@tonic-gate atomic_or_uint_nv(volatile uint_t *target, uint_t value)
319*0Sstevel@tonic-gate { return (*target |= value); }
320*0Sstevel@tonic-gate 
321*0Sstevel@tonic-gate ulong_t
322*0Sstevel@tonic-gate atomic_or_ulong_nv(volatile ulong_t *target, ulong_t value)
323*0Sstevel@tonic-gate { return (*target |= value); }
324*0Sstevel@tonic-gate 
325*0Sstevel@tonic-gate uint64_t
326*0Sstevel@tonic-gate atomic_or_64_nv(volatile uint64_t *target, uint64_t value)
327*0Sstevel@tonic-gate { return (*target |= value); }
328*0Sstevel@tonic-gate 
329*0Sstevel@tonic-gate uint8_t
330*0Sstevel@tonic-gate atomic_and_8_nv(volatile uint8_t *target, uint8_t value)
331*0Sstevel@tonic-gate { return (*target &= value); }
332*0Sstevel@tonic-gate 
333*0Sstevel@tonic-gate uchar_t
334*0Sstevel@tonic-gate atomic_and_uchar_nv(volatile uchar_t *target, uchar_t value)
335*0Sstevel@tonic-gate { return (*target &= value); }
336*0Sstevel@tonic-gate 
337*0Sstevel@tonic-gate uint16_t
338*0Sstevel@tonic-gate atomic_and_16_nv(volatile uint16_t *target, uint16_t value)
339*0Sstevel@tonic-gate { return (*target &= value); }
340*0Sstevel@tonic-gate 
341*0Sstevel@tonic-gate ushort_t
342*0Sstevel@tonic-gate atomic_and_ushort_nv(volatile ushort_t *target, ushort_t value)
343*0Sstevel@tonic-gate { return (*target &= value); }
344*0Sstevel@tonic-gate 
345*0Sstevel@tonic-gate uint32_t
346*0Sstevel@tonic-gate atomic_and_32_nv(volatile uint32_t *target, uint32_t value)
347*0Sstevel@tonic-gate { return (*target &= value); }
348*0Sstevel@tonic-gate 
349*0Sstevel@tonic-gate uint_t
350*0Sstevel@tonic-gate atomic_and_uint_nv(volatile uint_t *target, uint_t value)
351*0Sstevel@tonic-gate { return (*target &= value); }
352*0Sstevel@tonic-gate 
353*0Sstevel@tonic-gate ulong_t
354*0Sstevel@tonic-gate atomic_and_ulong_nv(volatile ulong_t *target, ulong_t value)
355*0Sstevel@tonic-gate { return (*target &= value); }
356*0Sstevel@tonic-gate 
357*0Sstevel@tonic-gate uint64_t
358*0Sstevel@tonic-gate atomic_and_64_nv(volatile uint64_t *target, uint64_t value)
359*0Sstevel@tonic-gate { return (*target &= value); }
360*0Sstevel@tonic-gate 
361*0Sstevel@tonic-gate uint8_t
362*0Sstevel@tonic-gate atomic_cas_8(volatile uint8_t *target, uint8_t cmp, uint8_t new)
363*0Sstevel@tonic-gate {
364*0Sstevel@tonic-gate 	uint8_t old = *target;
365*0Sstevel@tonic-gate 	if (old == cmp)
366*0Sstevel@tonic-gate 		*target = new;
367*0Sstevel@tonic-gate 	return (old);
368*0Sstevel@tonic-gate }
369*0Sstevel@tonic-gate 
370*0Sstevel@tonic-gate uchar_t
371*0Sstevel@tonic-gate atomic_cas_uchar(volatile uchar_t *target, uchar_t cmp, uchar_t new)
372*0Sstevel@tonic-gate {
373*0Sstevel@tonic-gate 	uchar_t old = *target;
374*0Sstevel@tonic-gate 	if (old == cmp)
375*0Sstevel@tonic-gate 		*target = new;
376*0Sstevel@tonic-gate 	return (old);
377*0Sstevel@tonic-gate }
378*0Sstevel@tonic-gate 
379*0Sstevel@tonic-gate uint16_t
380*0Sstevel@tonic-gate atomic_cas_16(volatile uint16_t *target, uint16_t cmp, uint16_t new)
381*0Sstevel@tonic-gate {
382*0Sstevel@tonic-gate 	uint16_t old = *target;
383*0Sstevel@tonic-gate 	if (old == cmp)
384*0Sstevel@tonic-gate 		*target = new;
385*0Sstevel@tonic-gate 	return (old);
386*0Sstevel@tonic-gate }
387*0Sstevel@tonic-gate 
388*0Sstevel@tonic-gate ushort_t
389*0Sstevel@tonic-gate atomic_cas_ushort(volatile ushort_t *target, ushort_t cmp, ushort_t new)
390*0Sstevel@tonic-gate {
391*0Sstevel@tonic-gate 	ushort_t old = *target;
392*0Sstevel@tonic-gate 	if (old == cmp)
393*0Sstevel@tonic-gate 		*target = new;
394*0Sstevel@tonic-gate 	return (old);
395*0Sstevel@tonic-gate }
396*0Sstevel@tonic-gate 
397*0Sstevel@tonic-gate uint32_t
398*0Sstevel@tonic-gate atomic_cas_32(volatile uint32_t *target, uint32_t cmp, uint32_t new)
399*0Sstevel@tonic-gate {
400*0Sstevel@tonic-gate 	uint32_t old = *target;
401*0Sstevel@tonic-gate 	if (old == cmp)
402*0Sstevel@tonic-gate 		*target = new;
403*0Sstevel@tonic-gate 	return (old);
404*0Sstevel@tonic-gate }
405*0Sstevel@tonic-gate 
406*0Sstevel@tonic-gate uint_t
407*0Sstevel@tonic-gate atomic_cas_uint(volatile uint_t *target, uint_t cmp, uint_t new)
408*0Sstevel@tonic-gate {
409*0Sstevel@tonic-gate 	uint_t old = *target;
410*0Sstevel@tonic-gate 	if (old == cmp)
411*0Sstevel@tonic-gate 		*target = new;
412*0Sstevel@tonic-gate 	return (old);
413*0Sstevel@tonic-gate }
414*0Sstevel@tonic-gate 
415*0Sstevel@tonic-gate ulong_t
416*0Sstevel@tonic-gate atomic_cas_ulong(volatile ulong_t *target, ulong_t cmp, ulong_t new)
417*0Sstevel@tonic-gate {
418*0Sstevel@tonic-gate 	ulong_t old = *target;
419*0Sstevel@tonic-gate 	if (old == cmp)
420*0Sstevel@tonic-gate 		*target = new;
421*0Sstevel@tonic-gate 	return (old);
422*0Sstevel@tonic-gate }
423*0Sstevel@tonic-gate 
424*0Sstevel@tonic-gate uint64_t
425*0Sstevel@tonic-gate atomic_cas_uint64(volatile uint64_t *target, ulong_t cmp, uint64_t new)
426*0Sstevel@tonic-gate {
427*0Sstevel@tonic-gate 	uint64_t old = *target;
428*0Sstevel@tonic-gate 	if (old == cmp)
429*0Sstevel@tonic-gate 		*target = new;
430*0Sstevel@tonic-gate 	return (old);
431*0Sstevel@tonic-gate }
432*0Sstevel@tonic-gate 
433*0Sstevel@tonic-gate void *
434*0Sstevel@tonic-gate atomic_cas_ptr(volatile void *target, void *cmp, void *new)
435*0Sstevel@tonic-gate {
436*0Sstevel@tonic-gate 	void *old = *(void **)target;
437*0Sstevel@tonic-gate 	if (old == cmp)
438*0Sstevel@tonic-gate 		*(void **)target = new;
439*0Sstevel@tonic-gate 	return (old);
440*0Sstevel@tonic-gate }
441*0Sstevel@tonic-gate 
442*0Sstevel@tonic-gate uint8_t
443*0Sstevel@tonic-gate atomic_swap_8(volatile uint8_t *target, uint8_t new)
444*0Sstevel@tonic-gate {
445*0Sstevel@tonic-gate 	uint8_t old = *target;
446*0Sstevel@tonic-gate 	*target = new;
447*0Sstevel@tonic-gate 	return (old);
448*0Sstevel@tonic-gate }
449*0Sstevel@tonic-gate 
450*0Sstevel@tonic-gate uchar_t
451*0Sstevel@tonic-gate atomic_swap_char(volatile uchar_t *target, uchar_t new)
452*0Sstevel@tonic-gate {
453*0Sstevel@tonic-gate 	uchar_t old = *target;
454*0Sstevel@tonic-gate 	*target = new;
455*0Sstevel@tonic-gate 	return (old);
456*0Sstevel@tonic-gate }
457*0Sstevel@tonic-gate 
458*0Sstevel@tonic-gate uint16_t
459*0Sstevel@tonic-gate atomic_swap_16(volatile uint16_t *target, uint16_t new)
460*0Sstevel@tonic-gate {
461*0Sstevel@tonic-gate 	uint16_t old = *target;
462*0Sstevel@tonic-gate 	*target = new;
463*0Sstevel@tonic-gate 	return (old);
464*0Sstevel@tonic-gate }
465*0Sstevel@tonic-gate 
466*0Sstevel@tonic-gate ushort_t
467*0Sstevel@tonic-gate atomic_swap_ushort(volatile ushort_t *target, ushort_t new)
468*0Sstevel@tonic-gate {
469*0Sstevel@tonic-gate 	ushort_t old = *target;
470*0Sstevel@tonic-gate 	*target = new;
471*0Sstevel@tonic-gate 	return (old);
472*0Sstevel@tonic-gate }
473*0Sstevel@tonic-gate 
474*0Sstevel@tonic-gate uint32_t
475*0Sstevel@tonic-gate atomic_swap_32(volatile uint32_t *target, uint32_t new)
476*0Sstevel@tonic-gate {
477*0Sstevel@tonic-gate 	uint32_t old = *target;
478*0Sstevel@tonic-gate 	*target = new;
479*0Sstevel@tonic-gate 	return (old);
480*0Sstevel@tonic-gate }
481*0Sstevel@tonic-gate 
482*0Sstevel@tonic-gate uint_t
483*0Sstevel@tonic-gate atomic_swap_uint(volatile uint_t *target, uint_t new)
484*0Sstevel@tonic-gate {
485*0Sstevel@tonic-gate 	ulong_t old = *target;
486*0Sstevel@tonic-gate 	*target = new;
487*0Sstevel@tonic-gate 	return (old);
488*0Sstevel@tonic-gate }
489*0Sstevel@tonic-gate 
490*0Sstevel@tonic-gate uint64_t
491*0Sstevel@tonic-gate atomic_swap_64(volatile uint64_t *target, uint64_t new)
492*0Sstevel@tonic-gate {
493*0Sstevel@tonic-gate 	uint64_t old = *target;
494*0Sstevel@tonic-gate 	*target = new;
495*0Sstevel@tonic-gate 	return (old);
496*0Sstevel@tonic-gate }
497*0Sstevel@tonic-gate 
498*0Sstevel@tonic-gate void *
499*0Sstevel@tonic-gate atomic_swap_ptr(volatile void *target, void *new)
500*0Sstevel@tonic-gate {
501*0Sstevel@tonic-gate 	void *old = *(void **)target;
502*0Sstevel@tonic-gate 	*(void **)target = new;
503*0Sstevel@tonic-gate 	return (old);
504*0Sstevel@tonic-gate }
505*0Sstevel@tonic-gate 
506*0Sstevel@tonic-gate ulong_t
507*0Sstevel@tonic-gate atomic_swap_ulong(volatile ulong_t *target, ulong_t new)
508*0Sstevel@tonic-gate {
509*0Sstevel@tonic-gate 	ulong_t old = *target;
510*0Sstevel@tonic-gate 	*target = new;
511*0Sstevel@tonic-gate 	return (old);
512*0Sstevel@tonic-gate }
513*0Sstevel@tonic-gate 
514*0Sstevel@tonic-gate int
515*0Sstevel@tonic-gate atomic_set_long_excl(volatile ulong_t *target, uint_t value)
516*0Sstevel@tonic-gate {
517*0Sstevel@tonic-gate 	ulong_t bit = (1UL << value);
518*0Sstevel@tonic-gate 	if ((*target & bit) != 0)
519*0Sstevel@tonic-gate 		return (-1);
520*0Sstevel@tonic-gate 	*target |= bit;
521*0Sstevel@tonic-gate 	return (0);
522*0Sstevel@tonic-gate }
523*0Sstevel@tonic-gate 
524*0Sstevel@tonic-gate int
525*0Sstevel@tonic-gate atomic_clear_long_excl(volatile ulong_t *target, uint_t value)
526*0Sstevel@tonic-gate {
527*0Sstevel@tonic-gate 	ulong_t bit = (1UL << value);
528*0Sstevel@tonic-gate 	if ((*target & bit) == 0)
529*0Sstevel@tonic-gate 		return (-1);
530*0Sstevel@tonic-gate 	*target &= ~bit;
531*0Sstevel@tonic-gate 	return (0);
532*0Sstevel@tonic-gate }
533*0Sstevel@tonic-gate 
534*0Sstevel@tonic-gate #if !defined(_KERNEL)
535*0Sstevel@tonic-gate 
536*0Sstevel@tonic-gate void
537*0Sstevel@tonic-gate membar_enter(void)
538*0Sstevel@tonic-gate {}
539*0Sstevel@tonic-gate 
540*0Sstevel@tonic-gate void
541*0Sstevel@tonic-gate membar_exit(void)
542*0Sstevel@tonic-gate {}
543*0Sstevel@tonic-gate 
544*0Sstevel@tonic-gate void
545*0Sstevel@tonic-gate membar_producer(void)
546*0Sstevel@tonic-gate {}
547*0Sstevel@tonic-gate 
548*0Sstevel@tonic-gate void
549*0Sstevel@tonic-gate membar_consumer(void)
550*0Sstevel@tonic-gate {}
551*0Sstevel@tonic-gate 
552*0Sstevel@tonic-gate #endif	/* _KERNEL */
553*0Sstevel@tonic-gate 
554*0Sstevel@tonic-gate #endif	/* __lint */
555