xref: /titanic_51/usr/src/common/atomic/atomic.c (revision 31db3c262ff9ce08fba42c443ccd352d642deba4)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5b02e9a2dSsvemuri  * Common Development and Distribution License (the "License").
6b02e9a2dSsvemuri  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
21*31db3c26Sraf 
227c478bd9Sstevel@tonic-gate /*
23*31db3c26Sraf  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate  */
267c478bd9Sstevel@tonic-gate 
277c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate #include <sys/atomic.h>
307c478bd9Sstevel@tonic-gate 
317c478bd9Sstevel@tonic-gate /*
327c478bd9Sstevel@tonic-gate  * This file exists only for the purpose of running lint.
337c478bd9Sstevel@tonic-gate  */
347c478bd9Sstevel@tonic-gate 
357c478bd9Sstevel@tonic-gate #if defined(__lint)
367c478bd9Sstevel@tonic-gate 
377c478bd9Sstevel@tonic-gate void
387c478bd9Sstevel@tonic-gate atomic_inc_8(volatile uint8_t *target)
397c478bd9Sstevel@tonic-gate { (*target)++; }
407c478bd9Sstevel@tonic-gate 
417c478bd9Sstevel@tonic-gate void
427c478bd9Sstevel@tonic-gate atomic_inc_uchar(volatile uchar_t *target)
437c478bd9Sstevel@tonic-gate { (*target)++; }
447c478bd9Sstevel@tonic-gate 
457c478bd9Sstevel@tonic-gate void
467c478bd9Sstevel@tonic-gate atomic_inc_16(volatile uint16_t *target)
477c478bd9Sstevel@tonic-gate { (*target)++; }
487c478bd9Sstevel@tonic-gate 
497c478bd9Sstevel@tonic-gate void
507c478bd9Sstevel@tonic-gate atomic_inc_ushort(volatile ushort_t *target)
517c478bd9Sstevel@tonic-gate { (*target)++; }
527c478bd9Sstevel@tonic-gate 
537c478bd9Sstevel@tonic-gate void
547c478bd9Sstevel@tonic-gate atomic_inc_32(volatile uint32_t *target)
557c478bd9Sstevel@tonic-gate { (*target)++; }
567c478bd9Sstevel@tonic-gate 
577c478bd9Sstevel@tonic-gate void
587c478bd9Sstevel@tonic-gate atomic_inc_uint(volatile uint_t *target)
597c478bd9Sstevel@tonic-gate { (*target)++; }
607c478bd9Sstevel@tonic-gate 
617c478bd9Sstevel@tonic-gate void
627c478bd9Sstevel@tonic-gate atomic_inc_ulong(volatile ulong_t *target)
637c478bd9Sstevel@tonic-gate { (*target)++; }
647c478bd9Sstevel@tonic-gate 
657c478bd9Sstevel@tonic-gate void
667c478bd9Sstevel@tonic-gate atomic_inc_64(volatile uint64_t *target)
677c478bd9Sstevel@tonic-gate { (*target)++; }
687c478bd9Sstevel@tonic-gate 
697c478bd9Sstevel@tonic-gate void
707c478bd9Sstevel@tonic-gate atomic_dec_8(volatile uint8_t *target)
717c478bd9Sstevel@tonic-gate { (*target)--; }
727c478bd9Sstevel@tonic-gate 
737c478bd9Sstevel@tonic-gate void
747c478bd9Sstevel@tonic-gate atomic_dec_uchar(volatile uchar_t *target)
757c478bd9Sstevel@tonic-gate { (*target)--; }
767c478bd9Sstevel@tonic-gate 
777c478bd9Sstevel@tonic-gate void
787c478bd9Sstevel@tonic-gate atomic_dec_16(volatile uint16_t *target)
797c478bd9Sstevel@tonic-gate { (*target)--; }
807c478bd9Sstevel@tonic-gate 
817c478bd9Sstevel@tonic-gate void
827c478bd9Sstevel@tonic-gate atomic_dec_ushort(volatile ushort_t *target)
837c478bd9Sstevel@tonic-gate { (*target)--; }
847c478bd9Sstevel@tonic-gate 
857c478bd9Sstevel@tonic-gate void
867c478bd9Sstevel@tonic-gate atomic_dec_32(volatile uint32_t *target)
877c478bd9Sstevel@tonic-gate { (*target)--; }
887c478bd9Sstevel@tonic-gate 
897c478bd9Sstevel@tonic-gate void
907c478bd9Sstevel@tonic-gate atomic_dec_uint(volatile uint_t *target)
917c478bd9Sstevel@tonic-gate { (*target)--; }
927c478bd9Sstevel@tonic-gate 
937c478bd9Sstevel@tonic-gate void
947c478bd9Sstevel@tonic-gate atomic_dec_ulong(volatile ulong_t *target)
957c478bd9Sstevel@tonic-gate { (*target)--; }
967c478bd9Sstevel@tonic-gate 
977c478bd9Sstevel@tonic-gate void
987c478bd9Sstevel@tonic-gate atomic_dec_64(volatile uint64_t *target)
997c478bd9Sstevel@tonic-gate { (*target)--; }
1007c478bd9Sstevel@tonic-gate 
1017c478bd9Sstevel@tonic-gate void
1027c478bd9Sstevel@tonic-gate atomic_add_8(volatile uint8_t *target, int8_t value)
1037c478bd9Sstevel@tonic-gate { *target += value; }
1047c478bd9Sstevel@tonic-gate 
1057c478bd9Sstevel@tonic-gate void
1067c478bd9Sstevel@tonic-gate atomic_add_char(volatile uchar_t *target, signed char value)
1077c478bd9Sstevel@tonic-gate { *target += value; }
1087c478bd9Sstevel@tonic-gate 
1097c478bd9Sstevel@tonic-gate void
1107c478bd9Sstevel@tonic-gate atomic_add_16(volatile uint16_t *target, int16_t delta)
1117c478bd9Sstevel@tonic-gate { *target += delta; }
1127c478bd9Sstevel@tonic-gate 
1137c478bd9Sstevel@tonic-gate void
1147c478bd9Sstevel@tonic-gate atomic_add_ushort(volatile ushort_t *target, short value)
1157c478bd9Sstevel@tonic-gate { *target += value; }
1167c478bd9Sstevel@tonic-gate 
1177c478bd9Sstevel@tonic-gate void
1187c478bd9Sstevel@tonic-gate atomic_add_32(volatile uint32_t *target, int32_t delta)
1197c478bd9Sstevel@tonic-gate { *target += delta; }
1207c478bd9Sstevel@tonic-gate 
1217c478bd9Sstevel@tonic-gate void
1227c478bd9Sstevel@tonic-gate atomic_add_ptr(volatile void *target, ssize_t value)
1237c478bd9Sstevel@tonic-gate { *(caddr_t *)target += value; }
1247c478bd9Sstevel@tonic-gate 
1257c478bd9Sstevel@tonic-gate void
1267c478bd9Sstevel@tonic-gate atomic_add_long(volatile ulong_t *target, long delta)
1277c478bd9Sstevel@tonic-gate { *target += delta; }
1287c478bd9Sstevel@tonic-gate 
1297c478bd9Sstevel@tonic-gate void
1307c478bd9Sstevel@tonic-gate atomic_add_64(volatile uint64_t *target, int64_t delta)
1317c478bd9Sstevel@tonic-gate { *target += delta; }
1327c478bd9Sstevel@tonic-gate 
1337c478bd9Sstevel@tonic-gate void
1347c478bd9Sstevel@tonic-gate atomic_or_8(volatile uint8_t *target, uint8_t bits)
1357c478bd9Sstevel@tonic-gate { *target |= bits; }
1367c478bd9Sstevel@tonic-gate 
1377c478bd9Sstevel@tonic-gate void
1387c478bd9Sstevel@tonic-gate atomic_or_uchar(volatile uchar_t *target, uchar_t bits)
1397c478bd9Sstevel@tonic-gate { *target |= bits; }
1407c478bd9Sstevel@tonic-gate 
1417c478bd9Sstevel@tonic-gate void
1427c478bd9Sstevel@tonic-gate atomic_or_16(volatile uint16_t *target, uint16_t bits)
1437c478bd9Sstevel@tonic-gate { *target |= bits; }
1447c478bd9Sstevel@tonic-gate 
1457c478bd9Sstevel@tonic-gate void
1467c478bd9Sstevel@tonic-gate atomic_or_ushort(volatile ushort_t *target, ushort_t bits)
1477c478bd9Sstevel@tonic-gate { *target |= bits; }
1487c478bd9Sstevel@tonic-gate 
1497c478bd9Sstevel@tonic-gate void
1507c478bd9Sstevel@tonic-gate atomic_or_32(volatile uint32_t *target, uint32_t bits)
1517c478bd9Sstevel@tonic-gate { *target |= bits; }
1527c478bd9Sstevel@tonic-gate 
1537c478bd9Sstevel@tonic-gate void
1547c478bd9Sstevel@tonic-gate atomic_or_uint(volatile uint_t *target, uint_t bits)
1557c478bd9Sstevel@tonic-gate { *target |= bits; }
1567c478bd9Sstevel@tonic-gate 
1577c478bd9Sstevel@tonic-gate void
1587c478bd9Sstevel@tonic-gate atomic_or_ulong(volatile ulong_t *target, ulong_t bits)
1597c478bd9Sstevel@tonic-gate { *target |= bits; }
1607c478bd9Sstevel@tonic-gate 
1617c478bd9Sstevel@tonic-gate void
1627c478bd9Sstevel@tonic-gate atomic_or_64(volatile uint64_t *target, uint64_t bits)
1637c478bd9Sstevel@tonic-gate { *target |= bits; }
1647c478bd9Sstevel@tonic-gate 
1657c478bd9Sstevel@tonic-gate void
1667c478bd9Sstevel@tonic-gate atomic_and_8(volatile uint8_t *target, uint8_t bits)
1677c478bd9Sstevel@tonic-gate { *target &= bits; }
1687c478bd9Sstevel@tonic-gate 
1697c478bd9Sstevel@tonic-gate void
1707c478bd9Sstevel@tonic-gate atomic_and_uchar(volatile uchar_t *target, uchar_t bits)
1717c478bd9Sstevel@tonic-gate { *target &= bits; }
1727c478bd9Sstevel@tonic-gate 
1737c478bd9Sstevel@tonic-gate void
1747c478bd9Sstevel@tonic-gate atomic_and_16(volatile uint16_t *target, uint16_t bits)
1757c478bd9Sstevel@tonic-gate { *target &= bits; }
1767c478bd9Sstevel@tonic-gate 
1777c478bd9Sstevel@tonic-gate void
1787c478bd9Sstevel@tonic-gate atomic_and_ushort(volatile ushort_t *target, ushort_t bits)
1797c478bd9Sstevel@tonic-gate { *target &= bits; }
1807c478bd9Sstevel@tonic-gate 
1817c478bd9Sstevel@tonic-gate void
1827c478bd9Sstevel@tonic-gate atomic_and_32(volatile uint32_t *target, uint32_t bits)
1837c478bd9Sstevel@tonic-gate { *target &= bits; }
1847c478bd9Sstevel@tonic-gate 
1857c478bd9Sstevel@tonic-gate void
1867c478bd9Sstevel@tonic-gate atomic_and_uint(volatile uint_t *target, uint_t bits)
1877c478bd9Sstevel@tonic-gate { *target &= bits; }
1887c478bd9Sstevel@tonic-gate 
1897c478bd9Sstevel@tonic-gate void
1907c478bd9Sstevel@tonic-gate atomic_and_ulong(volatile ulong_t *target, ulong_t bits)
1917c478bd9Sstevel@tonic-gate { *target &= bits; }
1927c478bd9Sstevel@tonic-gate 
1937c478bd9Sstevel@tonic-gate void
1947c478bd9Sstevel@tonic-gate atomic_and_64(volatile uint64_t *target, uint64_t bits)
1957c478bd9Sstevel@tonic-gate { *target &= bits; }
1967c478bd9Sstevel@tonic-gate 
1977c478bd9Sstevel@tonic-gate uint8_t
1987c478bd9Sstevel@tonic-gate atomic_inc_8_nv(volatile uint8_t *target)
1997c478bd9Sstevel@tonic-gate { return (++(*target)); }
2007c478bd9Sstevel@tonic-gate 
2017c478bd9Sstevel@tonic-gate uchar_t
2027c478bd9Sstevel@tonic-gate atomic_inc_uchar_nv(volatile uchar_t *target)
2037c478bd9Sstevel@tonic-gate { return (++(*target)); }
2047c478bd9Sstevel@tonic-gate 
2057c478bd9Sstevel@tonic-gate uint16_t
2067c478bd9Sstevel@tonic-gate atomic_inc_16_nv(volatile uint16_t *target)
2077c478bd9Sstevel@tonic-gate { return (++(*target)); }
2087c478bd9Sstevel@tonic-gate 
2097c478bd9Sstevel@tonic-gate ushort_t
2107c478bd9Sstevel@tonic-gate atomic_inc_ushort_nv(volatile ushort_t *target)
2117c478bd9Sstevel@tonic-gate { return (++(*target)); }
2127c478bd9Sstevel@tonic-gate 
2137c478bd9Sstevel@tonic-gate uint32_t
2147c478bd9Sstevel@tonic-gate atomic_inc_32_nv(volatile uint32_t *target)
2157c478bd9Sstevel@tonic-gate { return (++(*target)); }
2167c478bd9Sstevel@tonic-gate 
2177c478bd9Sstevel@tonic-gate uint_t
2187c478bd9Sstevel@tonic-gate atomic_inc_uint_nv(volatile uint_t *target)
2197c478bd9Sstevel@tonic-gate { return (++(*target)); }
2207c478bd9Sstevel@tonic-gate 
2217c478bd9Sstevel@tonic-gate ulong_t
2227c478bd9Sstevel@tonic-gate atomic_inc_ulong_nv(volatile ulong_t *target)
2237c478bd9Sstevel@tonic-gate { return (++(*target)); }
2247c478bd9Sstevel@tonic-gate 
2257c478bd9Sstevel@tonic-gate uint64_t
2267c478bd9Sstevel@tonic-gate atomic_inc_64_nv(volatile uint64_t *target)
2277c478bd9Sstevel@tonic-gate { return (++(*target)); }
2287c478bd9Sstevel@tonic-gate 
2297c478bd9Sstevel@tonic-gate uint8_t
2307c478bd9Sstevel@tonic-gate atomic_dec_8_nv(volatile uint8_t *target)
2317c478bd9Sstevel@tonic-gate { return (--(*target)); }
2327c478bd9Sstevel@tonic-gate 
2337c478bd9Sstevel@tonic-gate uchar_t
2347c478bd9Sstevel@tonic-gate atomic_dec_uchar_nv(volatile uchar_t *target)
2357c478bd9Sstevel@tonic-gate { return (--(*target)); }
2367c478bd9Sstevel@tonic-gate 
2377c478bd9Sstevel@tonic-gate uint16_t
2387c478bd9Sstevel@tonic-gate atomic_dec_16_nv(volatile uint16_t *target)
2397c478bd9Sstevel@tonic-gate { return (--(*target)); }
2407c478bd9Sstevel@tonic-gate 
2417c478bd9Sstevel@tonic-gate ushort_t
2427c478bd9Sstevel@tonic-gate atomic_dec_ushort_nv(volatile ushort_t *target)
2437c478bd9Sstevel@tonic-gate { return (--(*target)); }
2447c478bd9Sstevel@tonic-gate 
2457c478bd9Sstevel@tonic-gate uint32_t
2467c478bd9Sstevel@tonic-gate atomic_dec_32_nv(volatile uint32_t *target)
2477c478bd9Sstevel@tonic-gate { return (--(*target)); }
2487c478bd9Sstevel@tonic-gate 
2497c478bd9Sstevel@tonic-gate uint_t
2507c478bd9Sstevel@tonic-gate atomic_dec_uint_nv(volatile uint_t *target)
2517c478bd9Sstevel@tonic-gate { return (--(*target)); }
2527c478bd9Sstevel@tonic-gate 
2537c478bd9Sstevel@tonic-gate ulong_t
2547c478bd9Sstevel@tonic-gate atomic_dec_ulong_nv(volatile ulong_t *target)
2557c478bd9Sstevel@tonic-gate { return (--(*target)); }
2567c478bd9Sstevel@tonic-gate 
2577c478bd9Sstevel@tonic-gate uint64_t
2587c478bd9Sstevel@tonic-gate atomic_dec_64_nv(volatile uint64_t *target)
2597c478bd9Sstevel@tonic-gate { return (--(*target)); }
2607c478bd9Sstevel@tonic-gate 
2617c478bd9Sstevel@tonic-gate uint8_t
2627c478bd9Sstevel@tonic-gate atomic_add_8_nv(volatile uint8_t *target, int8_t value)
2637c478bd9Sstevel@tonic-gate { return (*target += value); }
2647c478bd9Sstevel@tonic-gate 
2657c478bd9Sstevel@tonic-gate uchar_t
2667c478bd9Sstevel@tonic-gate atomic_add_char_nv(volatile uchar_t *target, signed char value)
2677c478bd9Sstevel@tonic-gate { return (*target += value); }
2687c478bd9Sstevel@tonic-gate 
2697c478bd9Sstevel@tonic-gate uint16_t
2707c478bd9Sstevel@tonic-gate atomic_add_16_nv(volatile uint16_t *target, int16_t delta)
2717c478bd9Sstevel@tonic-gate { return (*target += delta); }
2727c478bd9Sstevel@tonic-gate 
2737c478bd9Sstevel@tonic-gate ushort_t
2747c478bd9Sstevel@tonic-gate atomic_add_short_nv(volatile ushort_t *target, short value)
2757c478bd9Sstevel@tonic-gate { return (*target += value); }
2767c478bd9Sstevel@tonic-gate 
2777c478bd9Sstevel@tonic-gate uint32_t
2787c478bd9Sstevel@tonic-gate atomic_add_32_nv(volatile uint32_t *target, int32_t delta)
2797c478bd9Sstevel@tonic-gate { return (*target += delta); }
2807c478bd9Sstevel@tonic-gate 
2817c478bd9Sstevel@tonic-gate uint_t
2827c478bd9Sstevel@tonic-gate atomic_add_int_nv(volatile uint_t *target, int delta)
2837c478bd9Sstevel@tonic-gate { return (*target += delta); }
2847c478bd9Sstevel@tonic-gate 
2857c478bd9Sstevel@tonic-gate void *
2867c478bd9Sstevel@tonic-gate atomic_add_ptr_nv(volatile void *target, ssize_t value)
2877c478bd9Sstevel@tonic-gate { return (*(caddr_t *)target += value); }
2887c478bd9Sstevel@tonic-gate 
2897c478bd9Sstevel@tonic-gate ulong_t
2907c478bd9Sstevel@tonic-gate atomic_add_long_nv(volatile ulong_t *target, long delta)
2917c478bd9Sstevel@tonic-gate { return (*target += delta); }
2927c478bd9Sstevel@tonic-gate 
2937c478bd9Sstevel@tonic-gate uint64_t
2947c478bd9Sstevel@tonic-gate atomic_add_64_nv(volatile uint64_t *target, int64_t delta)
2957c478bd9Sstevel@tonic-gate { return (*target += delta); }
2967c478bd9Sstevel@tonic-gate 
2977c478bd9Sstevel@tonic-gate uint8_t
2987c478bd9Sstevel@tonic-gate atomic_or_8_nv(volatile uint8_t *target, uint8_t value)
2997c478bd9Sstevel@tonic-gate { return (*target |= value); }
3007c478bd9Sstevel@tonic-gate 
3017c478bd9Sstevel@tonic-gate uchar_t
3027c478bd9Sstevel@tonic-gate atomic_or_uchar_nv(volatile uchar_t *target, uchar_t value)
3037c478bd9Sstevel@tonic-gate { return (*target |= value); }
3047c478bd9Sstevel@tonic-gate 
3057c478bd9Sstevel@tonic-gate uint16_t
3067c478bd9Sstevel@tonic-gate atomic_or_16_nv(volatile uint16_t *target, uint16_t value)
3077c478bd9Sstevel@tonic-gate { return (*target |= value); }
3087c478bd9Sstevel@tonic-gate 
3097c478bd9Sstevel@tonic-gate ushort_t
3107c478bd9Sstevel@tonic-gate atomic_or_ushort_nv(volatile ushort_t *target, ushort_t value)
3117c478bd9Sstevel@tonic-gate { return (*target |= value); }
3127c478bd9Sstevel@tonic-gate 
3137c478bd9Sstevel@tonic-gate uint32_t
3147c478bd9Sstevel@tonic-gate atomic_or_32_nv(volatile uint32_t *target, uint32_t value)
3157c478bd9Sstevel@tonic-gate { return (*target |= value); }
3167c478bd9Sstevel@tonic-gate 
3177c478bd9Sstevel@tonic-gate uint_t
3187c478bd9Sstevel@tonic-gate atomic_or_uint_nv(volatile uint_t *target, uint_t value)
3197c478bd9Sstevel@tonic-gate { return (*target |= value); }
3207c478bd9Sstevel@tonic-gate 
3217c478bd9Sstevel@tonic-gate ulong_t
3227c478bd9Sstevel@tonic-gate atomic_or_ulong_nv(volatile ulong_t *target, ulong_t value)
3237c478bd9Sstevel@tonic-gate { return (*target |= value); }
3247c478bd9Sstevel@tonic-gate 
3257c478bd9Sstevel@tonic-gate uint64_t
3267c478bd9Sstevel@tonic-gate atomic_or_64_nv(volatile uint64_t *target, uint64_t value)
3277c478bd9Sstevel@tonic-gate { return (*target |= value); }
3287c478bd9Sstevel@tonic-gate 
3297c478bd9Sstevel@tonic-gate uint8_t
3307c478bd9Sstevel@tonic-gate atomic_and_8_nv(volatile uint8_t *target, uint8_t value)
3317c478bd9Sstevel@tonic-gate { return (*target &= value); }
3327c478bd9Sstevel@tonic-gate 
3337c478bd9Sstevel@tonic-gate uchar_t
3347c478bd9Sstevel@tonic-gate atomic_and_uchar_nv(volatile uchar_t *target, uchar_t value)
3357c478bd9Sstevel@tonic-gate { return (*target &= value); }
3367c478bd9Sstevel@tonic-gate 
3377c478bd9Sstevel@tonic-gate uint16_t
3387c478bd9Sstevel@tonic-gate atomic_and_16_nv(volatile uint16_t *target, uint16_t value)
3397c478bd9Sstevel@tonic-gate { return (*target &= value); }
3407c478bd9Sstevel@tonic-gate 
3417c478bd9Sstevel@tonic-gate ushort_t
3427c478bd9Sstevel@tonic-gate atomic_and_ushort_nv(volatile ushort_t *target, ushort_t value)
3437c478bd9Sstevel@tonic-gate { return (*target &= value); }
3447c478bd9Sstevel@tonic-gate 
3457c478bd9Sstevel@tonic-gate uint32_t
3467c478bd9Sstevel@tonic-gate atomic_and_32_nv(volatile uint32_t *target, uint32_t value)
3477c478bd9Sstevel@tonic-gate { return (*target &= value); }
3487c478bd9Sstevel@tonic-gate 
3497c478bd9Sstevel@tonic-gate uint_t
3507c478bd9Sstevel@tonic-gate atomic_and_uint_nv(volatile uint_t *target, uint_t value)
3517c478bd9Sstevel@tonic-gate { return (*target &= value); }
3527c478bd9Sstevel@tonic-gate 
3537c478bd9Sstevel@tonic-gate ulong_t
3547c478bd9Sstevel@tonic-gate atomic_and_ulong_nv(volatile ulong_t *target, ulong_t value)
3557c478bd9Sstevel@tonic-gate { return (*target &= value); }
3567c478bd9Sstevel@tonic-gate 
3577c478bd9Sstevel@tonic-gate uint64_t
3587c478bd9Sstevel@tonic-gate atomic_and_64_nv(volatile uint64_t *target, uint64_t value)
3597c478bd9Sstevel@tonic-gate { return (*target &= value); }
3607c478bd9Sstevel@tonic-gate 
3617c478bd9Sstevel@tonic-gate uint8_t
3627c478bd9Sstevel@tonic-gate atomic_cas_8(volatile uint8_t *target, uint8_t cmp, uint8_t new)
3637c478bd9Sstevel@tonic-gate {
3647c478bd9Sstevel@tonic-gate 	uint8_t old = *target;
3657c478bd9Sstevel@tonic-gate 	if (old == cmp)
3667c478bd9Sstevel@tonic-gate 		*target = new;
3677c478bd9Sstevel@tonic-gate 	return (old);
3687c478bd9Sstevel@tonic-gate }
3697c478bd9Sstevel@tonic-gate 
3707c478bd9Sstevel@tonic-gate uchar_t
3717c478bd9Sstevel@tonic-gate atomic_cas_uchar(volatile uchar_t *target, uchar_t cmp, uchar_t new)
3727c478bd9Sstevel@tonic-gate {
3737c478bd9Sstevel@tonic-gate 	uchar_t old = *target;
3747c478bd9Sstevel@tonic-gate 	if (old == cmp)
3757c478bd9Sstevel@tonic-gate 		*target = new;
3767c478bd9Sstevel@tonic-gate 	return (old);
3777c478bd9Sstevel@tonic-gate }
3787c478bd9Sstevel@tonic-gate 
3797c478bd9Sstevel@tonic-gate uint16_t
3807c478bd9Sstevel@tonic-gate atomic_cas_16(volatile uint16_t *target, uint16_t cmp, uint16_t new)
3817c478bd9Sstevel@tonic-gate {
3827c478bd9Sstevel@tonic-gate 	uint16_t old = *target;
3837c478bd9Sstevel@tonic-gate 	if (old == cmp)
3847c478bd9Sstevel@tonic-gate 		*target = new;
3857c478bd9Sstevel@tonic-gate 	return (old);
3867c478bd9Sstevel@tonic-gate }
3877c478bd9Sstevel@tonic-gate 
3887c478bd9Sstevel@tonic-gate ushort_t
3897c478bd9Sstevel@tonic-gate atomic_cas_ushort(volatile ushort_t *target, ushort_t cmp, ushort_t new)
3907c478bd9Sstevel@tonic-gate {
3917c478bd9Sstevel@tonic-gate 	ushort_t old = *target;
3927c478bd9Sstevel@tonic-gate 	if (old == cmp)
3937c478bd9Sstevel@tonic-gate 		*target = new;
3947c478bd9Sstevel@tonic-gate 	return (old);
3957c478bd9Sstevel@tonic-gate }
3967c478bd9Sstevel@tonic-gate 
3977c478bd9Sstevel@tonic-gate uint32_t
3987c478bd9Sstevel@tonic-gate atomic_cas_32(volatile uint32_t *target, uint32_t cmp, uint32_t new)
3997c478bd9Sstevel@tonic-gate {
4007c478bd9Sstevel@tonic-gate 	uint32_t old = *target;
4017c478bd9Sstevel@tonic-gate 	if (old == cmp)
4027c478bd9Sstevel@tonic-gate 		*target = new;
4037c478bd9Sstevel@tonic-gate 	return (old);
4047c478bd9Sstevel@tonic-gate }
4057c478bd9Sstevel@tonic-gate 
4067c478bd9Sstevel@tonic-gate uint_t
4077c478bd9Sstevel@tonic-gate atomic_cas_uint(volatile uint_t *target, uint_t cmp, uint_t new)
4087c478bd9Sstevel@tonic-gate {
4097c478bd9Sstevel@tonic-gate 	uint_t old = *target;
4107c478bd9Sstevel@tonic-gate 	if (old == cmp)
4117c478bd9Sstevel@tonic-gate 		*target = new;
4127c478bd9Sstevel@tonic-gate 	return (old);
4137c478bd9Sstevel@tonic-gate }
4147c478bd9Sstevel@tonic-gate 
4157c478bd9Sstevel@tonic-gate ulong_t
4167c478bd9Sstevel@tonic-gate atomic_cas_ulong(volatile ulong_t *target, ulong_t cmp, ulong_t new)
4177c478bd9Sstevel@tonic-gate {
4187c478bd9Sstevel@tonic-gate 	ulong_t old = *target;
4197c478bd9Sstevel@tonic-gate 	if (old == cmp)
4207c478bd9Sstevel@tonic-gate 		*target = new;
4217c478bd9Sstevel@tonic-gate 	return (old);
4227c478bd9Sstevel@tonic-gate }
4237c478bd9Sstevel@tonic-gate 
4247c478bd9Sstevel@tonic-gate uint64_t
425*31db3c26Sraf atomic_cas_64(volatile uint64_t *target, uint64_t cmp, uint64_t new)
4267c478bd9Sstevel@tonic-gate {
4277c478bd9Sstevel@tonic-gate 	uint64_t old = *target;
4287c478bd9Sstevel@tonic-gate 	if (old == cmp)
4297c478bd9Sstevel@tonic-gate 		*target = new;
4307c478bd9Sstevel@tonic-gate 	return (old);
4317c478bd9Sstevel@tonic-gate }
4327c478bd9Sstevel@tonic-gate 
4337c478bd9Sstevel@tonic-gate void *
4347c478bd9Sstevel@tonic-gate atomic_cas_ptr(volatile void *target, void *cmp, void *new)
4357c478bd9Sstevel@tonic-gate {
4367c478bd9Sstevel@tonic-gate 	void *old = *(void **)target;
4377c478bd9Sstevel@tonic-gate 	if (old == cmp)
4387c478bd9Sstevel@tonic-gate 		*(void **)target = new;
4397c478bd9Sstevel@tonic-gate 	return (old);
4407c478bd9Sstevel@tonic-gate }
4417c478bd9Sstevel@tonic-gate 
4427c478bd9Sstevel@tonic-gate uint8_t
4437c478bd9Sstevel@tonic-gate atomic_swap_8(volatile uint8_t *target, uint8_t new)
4447c478bd9Sstevel@tonic-gate {
4457c478bd9Sstevel@tonic-gate 	uint8_t old = *target;
4467c478bd9Sstevel@tonic-gate 	*target = new;
4477c478bd9Sstevel@tonic-gate 	return (old);
4487c478bd9Sstevel@tonic-gate }
4497c478bd9Sstevel@tonic-gate 
4507c478bd9Sstevel@tonic-gate uchar_t
4517c478bd9Sstevel@tonic-gate atomic_swap_char(volatile uchar_t *target, uchar_t new)
4527c478bd9Sstevel@tonic-gate {
4537c478bd9Sstevel@tonic-gate 	uchar_t old = *target;
4547c478bd9Sstevel@tonic-gate 	*target = new;
4557c478bd9Sstevel@tonic-gate 	return (old);
4567c478bd9Sstevel@tonic-gate }
4577c478bd9Sstevel@tonic-gate 
4587c478bd9Sstevel@tonic-gate uint16_t
4597c478bd9Sstevel@tonic-gate atomic_swap_16(volatile uint16_t *target, uint16_t new)
4607c478bd9Sstevel@tonic-gate {
4617c478bd9Sstevel@tonic-gate 	uint16_t old = *target;
4627c478bd9Sstevel@tonic-gate 	*target = new;
4637c478bd9Sstevel@tonic-gate 	return (old);
4647c478bd9Sstevel@tonic-gate }
4657c478bd9Sstevel@tonic-gate 
4667c478bd9Sstevel@tonic-gate ushort_t
4677c478bd9Sstevel@tonic-gate atomic_swap_ushort(volatile ushort_t *target, ushort_t new)
4687c478bd9Sstevel@tonic-gate {
4697c478bd9Sstevel@tonic-gate 	ushort_t old = *target;
4707c478bd9Sstevel@tonic-gate 	*target = new;
4717c478bd9Sstevel@tonic-gate 	return (old);
4727c478bd9Sstevel@tonic-gate }
4737c478bd9Sstevel@tonic-gate 
4747c478bd9Sstevel@tonic-gate uint32_t
4757c478bd9Sstevel@tonic-gate atomic_swap_32(volatile uint32_t *target, uint32_t new)
4767c478bd9Sstevel@tonic-gate {
4777c478bd9Sstevel@tonic-gate 	uint32_t old = *target;
4787c478bd9Sstevel@tonic-gate 	*target = new;
4797c478bd9Sstevel@tonic-gate 	return (old);
4807c478bd9Sstevel@tonic-gate }
4817c478bd9Sstevel@tonic-gate 
4827c478bd9Sstevel@tonic-gate uint_t
4837c478bd9Sstevel@tonic-gate atomic_swap_uint(volatile uint_t *target, uint_t new)
4847c478bd9Sstevel@tonic-gate {
485b02e9a2dSsvemuri 	uint_t old = *target;
4867c478bd9Sstevel@tonic-gate 	*target = new;
4877c478bd9Sstevel@tonic-gate 	return (old);
4887c478bd9Sstevel@tonic-gate }
4897c478bd9Sstevel@tonic-gate 
4907c478bd9Sstevel@tonic-gate uint64_t
4917c478bd9Sstevel@tonic-gate atomic_swap_64(volatile uint64_t *target, uint64_t new)
4927c478bd9Sstevel@tonic-gate {
4937c478bd9Sstevel@tonic-gate 	uint64_t old = *target;
4947c478bd9Sstevel@tonic-gate 	*target = new;
4957c478bd9Sstevel@tonic-gate 	return (old);
4967c478bd9Sstevel@tonic-gate }
4977c478bd9Sstevel@tonic-gate 
4987c478bd9Sstevel@tonic-gate void *
4997c478bd9Sstevel@tonic-gate atomic_swap_ptr(volatile void *target, void *new)
5007c478bd9Sstevel@tonic-gate {
5017c478bd9Sstevel@tonic-gate 	void *old = *(void **)target;
5027c478bd9Sstevel@tonic-gate 	*(void **)target = new;
5037c478bd9Sstevel@tonic-gate 	return (old);
5047c478bd9Sstevel@tonic-gate }
5057c478bd9Sstevel@tonic-gate 
5067c478bd9Sstevel@tonic-gate ulong_t
5077c478bd9Sstevel@tonic-gate atomic_swap_ulong(volatile ulong_t *target, ulong_t new)
5087c478bd9Sstevel@tonic-gate {
5097c478bd9Sstevel@tonic-gate 	ulong_t old = *target;
5107c478bd9Sstevel@tonic-gate 	*target = new;
5117c478bd9Sstevel@tonic-gate 	return (old);
5127c478bd9Sstevel@tonic-gate }
5137c478bd9Sstevel@tonic-gate 
5147c478bd9Sstevel@tonic-gate int
5157c478bd9Sstevel@tonic-gate atomic_set_long_excl(volatile ulong_t *target, uint_t value)
5167c478bd9Sstevel@tonic-gate {
5177c478bd9Sstevel@tonic-gate 	ulong_t bit = (1UL << value);
5187c478bd9Sstevel@tonic-gate 	if ((*target & bit) != 0)
5197c478bd9Sstevel@tonic-gate 		return (-1);
5207c478bd9Sstevel@tonic-gate 	*target |= bit;
5217c478bd9Sstevel@tonic-gate 	return (0);
5227c478bd9Sstevel@tonic-gate }
5237c478bd9Sstevel@tonic-gate 
5247c478bd9Sstevel@tonic-gate int
5257c478bd9Sstevel@tonic-gate atomic_clear_long_excl(volatile ulong_t *target, uint_t value)
5267c478bd9Sstevel@tonic-gate {
5277c478bd9Sstevel@tonic-gate 	ulong_t bit = (1UL << value);
5287c478bd9Sstevel@tonic-gate 	if ((*target & bit) == 0)
5297c478bd9Sstevel@tonic-gate 		return (-1);
5307c478bd9Sstevel@tonic-gate 	*target &= ~bit;
5317c478bd9Sstevel@tonic-gate 	return (0);
5327c478bd9Sstevel@tonic-gate }
5337c478bd9Sstevel@tonic-gate 
5347c478bd9Sstevel@tonic-gate #if !defined(_KERNEL)
5357c478bd9Sstevel@tonic-gate 
5367c478bd9Sstevel@tonic-gate void
5377c478bd9Sstevel@tonic-gate membar_enter(void)
5387c478bd9Sstevel@tonic-gate {}
5397c478bd9Sstevel@tonic-gate 
5407c478bd9Sstevel@tonic-gate void
5417c478bd9Sstevel@tonic-gate membar_exit(void)
5427c478bd9Sstevel@tonic-gate {}
5437c478bd9Sstevel@tonic-gate 
5447c478bd9Sstevel@tonic-gate void
5457c478bd9Sstevel@tonic-gate membar_producer(void)
5467c478bd9Sstevel@tonic-gate {}
5477c478bd9Sstevel@tonic-gate 
5487c478bd9Sstevel@tonic-gate void
5497c478bd9Sstevel@tonic-gate membar_consumer(void)
5507c478bd9Sstevel@tonic-gate {}
5517c478bd9Sstevel@tonic-gate 
5527c478bd9Sstevel@tonic-gate #endif	/* _KERNEL */
5537c478bd9Sstevel@tonic-gate 
5547c478bd9Sstevel@tonic-gate #endif	/* __lint */
555