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