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