10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*713Swesolows * Common Development and Distribution License (the "License"). 6*713Swesolows * You may not use this file except in compliance with the License. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 100Sstevel@tonic-gate * See the License for the specific language governing permissions 110Sstevel@tonic-gate * and limitations under the License. 120Sstevel@tonic-gate * 130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 180Sstevel@tonic-gate * 190Sstevel@tonic-gate * CDDL HEADER END 200Sstevel@tonic-gate */ 21*713Swesolows 220Sstevel@tonic-gate /* 230Sstevel@tonic-gate * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 240Sstevel@tonic-gate * Use is subject to license terms. 250Sstevel@tonic-gate */ 260Sstevel@tonic-gate 270Sstevel@tonic-gate #ifndef _SYS_ATOMIC_H 280Sstevel@tonic-gate #define _SYS_ATOMIC_H 290Sstevel@tonic-gate 300Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 310Sstevel@tonic-gate 320Sstevel@tonic-gate #include <sys/types.h> 330Sstevel@tonic-gate #include <sys/inttypes.h> 340Sstevel@tonic-gate 350Sstevel@tonic-gate #ifdef __cplusplus 360Sstevel@tonic-gate extern "C" { 370Sstevel@tonic-gate #endif 380Sstevel@tonic-gate 39*713Swesolows #if defined(_KERNEL) && defined(__GNUC__) && defined(_ASM_INLINES) && \ 40*713Swesolows (defined(__i386) || defined(__amd64)) 410Sstevel@tonic-gate #include <asm/atomic.h> 420Sstevel@tonic-gate #endif 430Sstevel@tonic-gate 440Sstevel@tonic-gate #if defined(_KERNEL) || defined(__STDC__) 450Sstevel@tonic-gate /* 460Sstevel@tonic-gate * Increment target. 470Sstevel@tonic-gate */ 480Sstevel@tonic-gate extern void atomic_inc_8(volatile uint8_t *); 490Sstevel@tonic-gate extern void atomic_inc_uchar(volatile uchar_t *); 500Sstevel@tonic-gate extern void atomic_inc_16(volatile uint16_t *); 510Sstevel@tonic-gate extern void atomic_inc_ushort(volatile ushort_t *); 520Sstevel@tonic-gate extern void atomic_inc_32(volatile uint32_t *); 530Sstevel@tonic-gate extern void atomic_inc_uint(volatile uint_t *); 540Sstevel@tonic-gate extern void atomic_inc_ulong(volatile ulong_t *); 550Sstevel@tonic-gate #if defined(_KERNEL) || defined(_INT64_TYPE) 560Sstevel@tonic-gate extern void atomic_inc_64(volatile uint64_t *); 570Sstevel@tonic-gate #endif 580Sstevel@tonic-gate 590Sstevel@tonic-gate /* 600Sstevel@tonic-gate * Decrement target 610Sstevel@tonic-gate */ 620Sstevel@tonic-gate extern void atomic_dec_8(volatile uint8_t *); 630Sstevel@tonic-gate extern void atomic_dec_uchar(volatile uchar_t *); 640Sstevel@tonic-gate extern void atomic_dec_16(volatile uint16_t *); 650Sstevel@tonic-gate extern void atomic_dec_ushort(volatile ushort_t *); 660Sstevel@tonic-gate extern void atomic_dec_32(volatile uint32_t *); 670Sstevel@tonic-gate extern void atomic_dec_uint(volatile uint_t *); 680Sstevel@tonic-gate extern void atomic_dec_ulong(volatile ulong_t *); 690Sstevel@tonic-gate #if defined(_KERNEL) || defined(_INT64_TYPE) 700Sstevel@tonic-gate extern void atomic_dec_64(volatile uint64_t *); 710Sstevel@tonic-gate #endif 720Sstevel@tonic-gate 730Sstevel@tonic-gate /* 740Sstevel@tonic-gate * Add delta to target 750Sstevel@tonic-gate */ 760Sstevel@tonic-gate extern void atomic_add_8(volatile uint8_t *, int8_t); 770Sstevel@tonic-gate extern void atomic_add_char(volatile uchar_t *, signed char); 780Sstevel@tonic-gate extern void atomic_add_16(volatile uint16_t *, int16_t); 790Sstevel@tonic-gate extern void atomic_add_short(volatile ushort_t *, short); 800Sstevel@tonic-gate extern void atomic_add_32(volatile uint32_t *, int32_t); 810Sstevel@tonic-gate extern void atomic_add_int(volatile uint_t *, int); 820Sstevel@tonic-gate extern void atomic_add_ptr(volatile void *, ssize_t); 830Sstevel@tonic-gate extern void atomic_add_long(volatile ulong_t *, long); 840Sstevel@tonic-gate #if defined(_KERNEL) || defined(_INT64_TYPE) 850Sstevel@tonic-gate extern void atomic_add_64(volatile uint64_t *, int64_t); 860Sstevel@tonic-gate #endif 870Sstevel@tonic-gate 880Sstevel@tonic-gate /* 890Sstevel@tonic-gate * logical OR bits with target 900Sstevel@tonic-gate */ 910Sstevel@tonic-gate extern void atomic_or_8(volatile uint8_t *, uint8_t); 920Sstevel@tonic-gate extern void atomic_or_uchar(volatile uchar_t *, uchar_t); 930Sstevel@tonic-gate extern void atomic_or_16(volatile uint16_t *, uint16_t); 940Sstevel@tonic-gate extern void atomic_or_ushort(volatile ushort_t *, ushort_t); 950Sstevel@tonic-gate extern void atomic_or_32(volatile uint32_t *, uint32_t); 960Sstevel@tonic-gate extern void atomic_or_uint(volatile uint_t *, uint_t); 970Sstevel@tonic-gate extern void atomic_or_ulong(volatile ulong_t *, ulong_t); 980Sstevel@tonic-gate #if defined(_KERNEL) || defined(_INT64_TYPE) 990Sstevel@tonic-gate extern void atomic_or_64(volatile uint64_t *, uint64_t); 1000Sstevel@tonic-gate #endif 1010Sstevel@tonic-gate 1020Sstevel@tonic-gate /* 1030Sstevel@tonic-gate * logical AND bits with target 1040Sstevel@tonic-gate */ 1050Sstevel@tonic-gate extern void atomic_and_8(volatile uint8_t *, uint8_t); 1060Sstevel@tonic-gate extern void atomic_and_uchar(volatile uchar_t *, uchar_t); 1070Sstevel@tonic-gate extern void atomic_and_16(volatile uint16_t *, uint16_t); 1080Sstevel@tonic-gate extern void atomic_and_ushort(volatile ushort_t *, ushort_t); 1090Sstevel@tonic-gate extern void atomic_and_32(volatile uint32_t *, uint32_t); 1100Sstevel@tonic-gate extern void atomic_and_uint(volatile uint_t *, uint_t); 1110Sstevel@tonic-gate extern void atomic_and_ulong(volatile ulong_t *, ulong_t); 1120Sstevel@tonic-gate #if defined(_KERNEL) || defined(_INT64_TYPE) 1130Sstevel@tonic-gate extern void atomic_and_64(volatile uint64_t *, uint64_t); 1140Sstevel@tonic-gate #endif 1150Sstevel@tonic-gate 1160Sstevel@tonic-gate /* 1170Sstevel@tonic-gate * As above, but return the new value. Note that these _nv() variants are 1180Sstevel@tonic-gate * substantially more expensive on some platforms than the no-return-value 1190Sstevel@tonic-gate * versions above, so don't use them unless you really need to know the 1200Sstevel@tonic-gate * new value *atomically* (e.g. when decrementing a reference count and 1210Sstevel@tonic-gate * checking whether it went to zero). 1220Sstevel@tonic-gate */ 1230Sstevel@tonic-gate 1240Sstevel@tonic-gate /* 1250Sstevel@tonic-gate * Increment target and return new value. 1260Sstevel@tonic-gate */ 1270Sstevel@tonic-gate extern uint8_t atomic_inc_8_nv(volatile uint8_t *); 1280Sstevel@tonic-gate extern uchar_t atomic_inc_uchar_nv(volatile uchar_t *); 1290Sstevel@tonic-gate extern uint16_t atomic_inc_16_nv(volatile uint16_t *); 1300Sstevel@tonic-gate extern ushort_t atomic_inc_ushort_nv(volatile ushort_t *); 1310Sstevel@tonic-gate extern uint32_t atomic_inc_32_nv(volatile uint32_t *); 1320Sstevel@tonic-gate extern uint_t atomic_inc_uint_nv(volatile uint_t *); 1330Sstevel@tonic-gate extern ulong_t atomic_inc_ulong_nv(volatile ulong_t *); 1340Sstevel@tonic-gate #if defined(_KERNEL) || defined(_INT64_TYPE) 1350Sstevel@tonic-gate extern uint64_t atomic_inc_64_nv(volatile uint64_t *); 1360Sstevel@tonic-gate #endif 1370Sstevel@tonic-gate 1380Sstevel@tonic-gate /* 1390Sstevel@tonic-gate * Decrement target and return new value. 1400Sstevel@tonic-gate */ 1410Sstevel@tonic-gate extern uint8_t atomic_dec_8_nv(volatile uint8_t *); 1420Sstevel@tonic-gate extern uchar_t atomic_dec_uchar_nv(volatile uchar_t *); 1430Sstevel@tonic-gate extern uint16_t atomic_dec_16_nv(volatile uint16_t *); 1440Sstevel@tonic-gate extern ushort_t atomic_dec_ushort_nv(volatile ushort_t *); 1450Sstevel@tonic-gate extern uint32_t atomic_dec_32_nv(volatile uint32_t *); 1460Sstevel@tonic-gate extern uint_t atomic_dec_uint_nv(volatile uint_t *); 1470Sstevel@tonic-gate extern ulong_t atomic_dec_ulong_nv(volatile ulong_t *); 1480Sstevel@tonic-gate #if defined(_KERNEL) || defined(_INT64_TYPE) 1490Sstevel@tonic-gate extern uint64_t atomic_dec_64_nv(volatile uint64_t *); 1500Sstevel@tonic-gate #endif 1510Sstevel@tonic-gate 1520Sstevel@tonic-gate /* 1530Sstevel@tonic-gate * Add delta to target 1540Sstevel@tonic-gate */ 1550Sstevel@tonic-gate extern uint8_t atomic_add_8_nv(volatile uint8_t *, int8_t); 1560Sstevel@tonic-gate extern uchar_t atomic_add_char_nv(volatile uchar_t *, signed char); 1570Sstevel@tonic-gate extern uint16_t atomic_add_16_nv(volatile uint16_t *, int16_t); 1580Sstevel@tonic-gate extern ushort_t atomic_add_short_nv(volatile ushort_t *, short); 1590Sstevel@tonic-gate extern uint32_t atomic_add_32_nv(volatile uint32_t *, int32_t); 1600Sstevel@tonic-gate extern uint_t atomic_add_int_nv(volatile uint_t *, int); 1610Sstevel@tonic-gate extern void *atomic_add_ptr_nv(volatile void *, ssize_t); 1620Sstevel@tonic-gate extern ulong_t atomic_add_long_nv(volatile ulong_t *, long); 1630Sstevel@tonic-gate #if defined(_KERNEL) || defined(_INT64_TYPE) 1640Sstevel@tonic-gate extern uint64_t atomic_add_64_nv(volatile uint64_t *, int64_t); 1650Sstevel@tonic-gate #endif 1660Sstevel@tonic-gate 1670Sstevel@tonic-gate /* 1680Sstevel@tonic-gate * logical OR bits with target and return new value. 1690Sstevel@tonic-gate */ 1700Sstevel@tonic-gate extern uint8_t atomic_or_8_nv(volatile uint8_t *, uint8_t); 1710Sstevel@tonic-gate extern uchar_t atomic_or_uchar_nv(volatile uchar_t *, uchar_t); 1720Sstevel@tonic-gate extern uint16_t atomic_or_16_nv(volatile uint16_t *, uint16_t); 1730Sstevel@tonic-gate extern ushort_t atomic_or_ushort_nv(volatile ushort_t *, ushort_t); 1740Sstevel@tonic-gate extern uint32_t atomic_or_32_nv(volatile uint32_t *, uint32_t); 1750Sstevel@tonic-gate extern uint_t atomic_or_uint_nv(volatile uint_t *, uint_t); 1760Sstevel@tonic-gate extern ulong_t atomic_or_ulong_nv(volatile ulong_t *, ulong_t); 1770Sstevel@tonic-gate #if defined(_KERNEL) || defined(_INT64_TYPE) 1780Sstevel@tonic-gate extern uint64_t atomic_or_64_nv(volatile uint64_t *, uint64_t); 1790Sstevel@tonic-gate #endif 1800Sstevel@tonic-gate 1810Sstevel@tonic-gate /* 1820Sstevel@tonic-gate * logical AND bits with target and return new value. 1830Sstevel@tonic-gate */ 1840Sstevel@tonic-gate extern uint8_t atomic_and_8_nv(volatile uint8_t *, uint8_t); 1850Sstevel@tonic-gate extern uchar_t atomic_and_uchar_nv(volatile uchar_t *, uchar_t); 1860Sstevel@tonic-gate extern uint16_t atomic_and_16_nv(volatile uint16_t *, uint16_t); 1870Sstevel@tonic-gate extern ushort_t atomic_and_ushort_nv(volatile ushort_t *, ushort_t); 1880Sstevel@tonic-gate extern uint32_t atomic_and_32_nv(volatile uint32_t *, uint32_t); 1890Sstevel@tonic-gate extern uint_t atomic_and_uint_nv(volatile uint_t *, uint_t); 1900Sstevel@tonic-gate extern ulong_t atomic_and_ulong_nv(volatile ulong_t *, ulong_t); 1910Sstevel@tonic-gate #if defined(_KERNEL) || defined(_INT64_TYPE) 1920Sstevel@tonic-gate extern uint64_t atomic_and_64_nv(volatile uint64_t *, uint64_t); 1930Sstevel@tonic-gate #endif 1940Sstevel@tonic-gate 1950Sstevel@tonic-gate /* 1960Sstevel@tonic-gate * If *arg1 == arg2, set *arg1 = arg3; return old value 1970Sstevel@tonic-gate */ 1980Sstevel@tonic-gate extern uint8_t atomic_cas_8(volatile uint8_t *, uint8_t, uint8_t); 1990Sstevel@tonic-gate extern uchar_t atomic_cas_uchar(volatile uchar_t *, uchar_t, uchar_t); 2000Sstevel@tonic-gate extern uint16_t atomic_cas_16(volatile uint16_t *, uint16_t, uint16_t); 2010Sstevel@tonic-gate extern ushort_t atomic_cas_ushort(volatile ushort_t *, ushort_t, ushort_t); 2020Sstevel@tonic-gate extern uint32_t atomic_cas_32(volatile uint32_t *, uint32_t, uint32_t); 2030Sstevel@tonic-gate extern uint_t atomic_cas_uint(volatile uint_t *, uint_t, uint_t); 2040Sstevel@tonic-gate extern void *atomic_cas_ptr(volatile void *, void *, void *); 2050Sstevel@tonic-gate extern ulong_t atomic_cas_ulong(volatile ulong_t *, ulong_t, ulong_t); 2060Sstevel@tonic-gate #if defined(_KERNEL) || defined(_INT64_TYPE) 2070Sstevel@tonic-gate extern uint64_t atomic_cas_64(volatile uint64_t *, uint64_t, uint64_t); 2080Sstevel@tonic-gate #endif 2090Sstevel@tonic-gate 2100Sstevel@tonic-gate /* 2110Sstevel@tonic-gate * Swap target and return old value 2120Sstevel@tonic-gate */ 2130Sstevel@tonic-gate extern uint8_t atomic_swap_8(volatile uint8_t *, uint8_t); 2140Sstevel@tonic-gate extern uchar_t atomic_swap_uchar(volatile uchar_t *, uchar_t); 2150Sstevel@tonic-gate extern uint16_t atomic_swap_16(volatile uint16_t *, uint16_t); 2160Sstevel@tonic-gate extern ushort_t atomic_swap_ushort(volatile ushort_t *, ushort_t); 2170Sstevel@tonic-gate extern uint32_t atomic_swap_32(volatile uint32_t *, uint32_t); 2180Sstevel@tonic-gate extern uint_t atomic_swap_uint(volatile uint_t *, uint_t); 2190Sstevel@tonic-gate extern void *atomic_swap_ptr(volatile void *, void *); 2200Sstevel@tonic-gate extern ulong_t atomic_swap_ulong(volatile ulong_t *, ulong_t); 2210Sstevel@tonic-gate #if defined(_KERNEL) || defined(_INT64_TYPE) 2220Sstevel@tonic-gate extern uint64_t atomic_swap_64(volatile uint64_t *, uint64_t); 2230Sstevel@tonic-gate #endif 2240Sstevel@tonic-gate 2250Sstevel@tonic-gate /* 2260Sstevel@tonic-gate * Perform an exclusive atomic bit set/clear on a target. 2270Sstevel@tonic-gate * Returns 0 if bit was sucessfully set/cleared, or -1 2280Sstevel@tonic-gate * if the bit was already set/cleared. 2290Sstevel@tonic-gate */ 2300Sstevel@tonic-gate extern int atomic_set_long_excl(volatile ulong_t *, uint_t); 2310Sstevel@tonic-gate extern int atomic_clear_long_excl(volatile ulong_t *, uint_t); 2320Sstevel@tonic-gate 2330Sstevel@tonic-gate /* 2340Sstevel@tonic-gate * Generic memory barrier used during lock entry, placed after the 2350Sstevel@tonic-gate * memory operation that acquires the lock to guarantee that the lock 2360Sstevel@tonic-gate * protects its data. No stores from after the memory barrier will 2370Sstevel@tonic-gate * reach visibility, and no loads from after the barrier will be 2380Sstevel@tonic-gate * resolved, before the lock acquisition reaches global visibility. 2390Sstevel@tonic-gate */ 2400Sstevel@tonic-gate extern void membar_enter(void); 2410Sstevel@tonic-gate 2420Sstevel@tonic-gate /* 2430Sstevel@tonic-gate * Generic memory barrier used during lock exit, placed before the 2440Sstevel@tonic-gate * memory operation that releases the lock to guarantee that the lock 2450Sstevel@tonic-gate * protects its data. All loads and stores issued before the barrier 2460Sstevel@tonic-gate * will be resolved before the subsequent lock update reaches visibility. 2470Sstevel@tonic-gate */ 2480Sstevel@tonic-gate extern void membar_exit(void); 2490Sstevel@tonic-gate 2500Sstevel@tonic-gate /* 2510Sstevel@tonic-gate * Arrange that all stores issued before this point in the code reach 2520Sstevel@tonic-gate * global visibility before any stores that follow; useful in producer 2530Sstevel@tonic-gate * modules that update a data item, then set a flag that it is available. 2540Sstevel@tonic-gate * The memory barrier guarantees that the available flag is not visible 2550Sstevel@tonic-gate * earlier than the updated data, i.e. it imposes store ordering. 2560Sstevel@tonic-gate */ 2570Sstevel@tonic-gate extern void membar_producer(void); 2580Sstevel@tonic-gate 2590Sstevel@tonic-gate /* 2600Sstevel@tonic-gate * Arrange that all loads issued before this point in the code are 2610Sstevel@tonic-gate * completed before any subsequent loads; useful in consumer modules 2620Sstevel@tonic-gate * that check to see if data is available and read the data. 2630Sstevel@tonic-gate * The memory barrier guarantees that the data is not sampled until 2640Sstevel@tonic-gate * after the available flag has been seen, i.e. it imposes load ordering. 2650Sstevel@tonic-gate */ 2660Sstevel@tonic-gate extern void membar_consumer(void); 2670Sstevel@tonic-gate #endif 2680Sstevel@tonic-gate 2690Sstevel@tonic-gate #if !defined(_KERNEL) && !defined(__STDC__) 2700Sstevel@tonic-gate extern void atomic_inc_8(); 2710Sstevel@tonic-gate extern void atomic_inc_uchar(); 2720Sstevel@tonic-gate extern void atomic_inc_16(); 2730Sstevel@tonic-gate extern void atomic_inc_ushort(); 2740Sstevel@tonic-gate extern void atomic_inc_32(); 2750Sstevel@tonic-gate extern void atomic_inc_uint(); 2760Sstevel@tonic-gate extern void atomic_inc_ulong(); 2770Sstevel@tonic-gate #if defined(_INT64_TYPE) 2780Sstevel@tonic-gate extern void atomic_inc_64(); 2790Sstevel@tonic-gate #endif /* defined(_INT64_TYPE) */ 2800Sstevel@tonic-gate extern void atomic_dec_8(); 2810Sstevel@tonic-gate extern void atomic_dec_uchar(); 2820Sstevel@tonic-gate extern void atomic_dec_16(); 2830Sstevel@tonic-gate extern void atomic_dec_ushort(); 2840Sstevel@tonic-gate extern void atomic_dec_32(); 2850Sstevel@tonic-gate extern void atomic_dec_uint(); 2860Sstevel@tonic-gate extern void atomic_dec_ulong(); 2870Sstevel@tonic-gate #if defined(_INT64_TYPE) 2880Sstevel@tonic-gate extern void atomic_dec_64(); 2890Sstevel@tonic-gate #endif /* defined(_INT64_TYPE) */ 2900Sstevel@tonic-gate extern void atomic_add_8(); 2910Sstevel@tonic-gate extern void atomic_add_char(); 2920Sstevel@tonic-gate extern void atomic_add_16(); 2930Sstevel@tonic-gate extern void atomic_add_short(); 2940Sstevel@tonic-gate extern void atomic_add_32(); 2950Sstevel@tonic-gate extern void atomic_add_int(); 2960Sstevel@tonic-gate extern void atomic_add_ptr(); 2970Sstevel@tonic-gate extern void atomic_add_long(); 2980Sstevel@tonic-gate #if defined(_INT64_TYPE) 2990Sstevel@tonic-gate extern void atomic_add_64(); 3000Sstevel@tonic-gate #endif /* defined(_INT64_TYPE) */ 3010Sstevel@tonic-gate extern void atomic_or_8(); 3020Sstevel@tonic-gate extern void atomic_or_uchar(); 3030Sstevel@tonic-gate extern void atomic_or_16(); 3040Sstevel@tonic-gate extern void atomic_or_ushort(); 3050Sstevel@tonic-gate extern void atomic_or_32(); 3060Sstevel@tonic-gate extern void atomic_or_uint(); 3070Sstevel@tonic-gate extern void atomic_or_ulong(); 3080Sstevel@tonic-gate #if defined(_INT64_TYPE) 3090Sstevel@tonic-gate extern void atomic_or_64(); 3100Sstevel@tonic-gate #endif /* defined(_INT64_TYPE) */ 3110Sstevel@tonic-gate extern void atomic_and_8(); 3120Sstevel@tonic-gate extern void atomic_and_uchar(); 3130Sstevel@tonic-gate extern void atomic_and_16(); 3140Sstevel@tonic-gate extern void atomic_and_ushort(); 3150Sstevel@tonic-gate extern void atomic_and_32(); 3160Sstevel@tonic-gate extern void atomic_and_uint(); 3170Sstevel@tonic-gate extern void atomic_and_ulong(); 3180Sstevel@tonic-gate #if defined(_INT64_TYPE) 3190Sstevel@tonic-gate extern void atomic_and_64(); 3200Sstevel@tonic-gate #endif /* defined(_INT64_TYPE) */ 3210Sstevel@tonic-gate extern uint8_t atomic_inc_8_nv(); 3220Sstevel@tonic-gate extern uchar_t atomic_inc_uchar_nv(); 3230Sstevel@tonic-gate extern uint16_t atomic_inc_16_nv(); 3240Sstevel@tonic-gate extern ushort_t atomic_inc_ushort_nv(); 3250Sstevel@tonic-gate extern uint32_t atomic_inc_32_nv(); 3260Sstevel@tonic-gate extern uint_t atomic_inc_uint_nv(); 3270Sstevel@tonic-gate extern ulong_t atomic_inc_ulong_nv(); 3280Sstevel@tonic-gate #if defined(_INT64_TYPE) 3290Sstevel@tonic-gate extern uint64_t atomic_inc_64_nv(); 3300Sstevel@tonic-gate #endif /* defined(_INT64_TYPE) */ 3310Sstevel@tonic-gate extern uint8_t atomic_dec_8_nv(); 3320Sstevel@tonic-gate extern uchar_t atomic_dec_uchar_nv(); 3330Sstevel@tonic-gate extern uint16_t atomic_dec_16_nv(); 3340Sstevel@tonic-gate extern ushort_t atomic_dec_ushort_nv(); 3350Sstevel@tonic-gate extern uint32_t atomic_dec_32_nv(); 3360Sstevel@tonic-gate extern uint_t atomic_dec_uint_nv(); 3370Sstevel@tonic-gate extern ulong_t atomic_dec_ulong_nv(); 3380Sstevel@tonic-gate #if defined(_INT64_TYPE) 3390Sstevel@tonic-gate extern uint64_t atomic_dec_64_nv(); 3400Sstevel@tonic-gate #endif /* defined(_INT64_TYPE) */ 3410Sstevel@tonic-gate extern uint8_t atomic_add_8_nv(); 3420Sstevel@tonic-gate extern uchar_t atomic_add_char_nv(); 3430Sstevel@tonic-gate extern uint16_t atomic_add_16_nv(); 3440Sstevel@tonic-gate extern ushort_t atomic_add_short_nv(); 3450Sstevel@tonic-gate extern uint32_t atomic_add_32_nv(); 3460Sstevel@tonic-gate extern uint_t atomic_add_int_nv(); 3470Sstevel@tonic-gate extern void *atomic_add_ptr_nv(); 3480Sstevel@tonic-gate extern ulong_t atomic_add_long_nv(); 3490Sstevel@tonic-gate #if defined(_INT64_TYPE) 3500Sstevel@tonic-gate extern uint64_t atomic_add_64_nv(); 3510Sstevel@tonic-gate #endif /* defined(_INT64_TYPE) */ 3520Sstevel@tonic-gate extern uint8_t atomic_or_8_nv(); 3530Sstevel@tonic-gate extern uchar_t atomic_or_uchar_nv(); 3540Sstevel@tonic-gate extern uint16_t atomic_or_16_nv(); 3550Sstevel@tonic-gate extern ushort_t atomic_or_ushort_nv(); 3560Sstevel@tonic-gate extern uint32_t atomic_or_32_nv(); 3570Sstevel@tonic-gate extern uint_t atomic_or_uint_nv(); 3580Sstevel@tonic-gate extern ulong_t atomic_or_ulong_nv(); 3590Sstevel@tonic-gate #if defined(_INT64_TYPE) 3600Sstevel@tonic-gate extern uint64_t atomic_or_64_nv(); 3610Sstevel@tonic-gate #endif /* defined(_INT64_TYPE) */ 3620Sstevel@tonic-gate extern uint8_t atomic_and_8_nv(); 3630Sstevel@tonic-gate extern uchar_t atomic_and_uchar_nv(); 3640Sstevel@tonic-gate extern uint16_t atomic_and_16_nv(); 3650Sstevel@tonic-gate extern ushort_t atomic_and_ushort_nv(); 3660Sstevel@tonic-gate extern uint32_t atomic_and_32_nv(); 3670Sstevel@tonic-gate extern uint_t atomic_and_uint_nv(); 3680Sstevel@tonic-gate extern ulong_t atomic_and_ulong_nv(); 3690Sstevel@tonic-gate #if defined(_INT64_TYPE) 3700Sstevel@tonic-gate extern uint64_t atomic_and_64_nv(); 3710Sstevel@tonic-gate #endif /* defined(_INT64_TYPE) */ 3720Sstevel@tonic-gate extern uint8_t atomic_cas_8(); 3730Sstevel@tonic-gate extern uchar_t atomic_cas_uchar(); 3740Sstevel@tonic-gate extern uint16_t atomic_cas_16(); 3750Sstevel@tonic-gate extern ushort_t atomic_cas_ushort(); 3760Sstevel@tonic-gate extern uint32_t atomic_cas_32(); 3770Sstevel@tonic-gate extern uint_t atomic_cas_uint(); 3780Sstevel@tonic-gate extern void *atomic_cas_ptr(); 3790Sstevel@tonic-gate extern ulong_t atomic_cas_ulong(); 3800Sstevel@tonic-gate #if defined(_INT64_TYPE) 3810Sstevel@tonic-gate extern uint64_t atomic_cas_64(); 3820Sstevel@tonic-gate #endif /* defined(_INT64_TYPE) */ 3830Sstevel@tonic-gate extern uint8_t atomic_swap_8(); 3840Sstevel@tonic-gate extern uchar_t atomic_swap_uchar(); 3850Sstevel@tonic-gate extern uint16_t atomic_swap_16(); 3860Sstevel@tonic-gate extern ushort_t atomic_swap_ushort(); 3870Sstevel@tonic-gate extern uint32_t atomic_swap_32(); 3880Sstevel@tonic-gate extern uint_t atomic_swap_uint(); 3890Sstevel@tonic-gate extern void *atomic_swap_ptr(); 3900Sstevel@tonic-gate extern ulong_t atomic_swap_ulong(); 3910Sstevel@tonic-gate #if defined(_INT64_TYPE) 3920Sstevel@tonic-gate extern uint64_t atomic_swap_64(); 3930Sstevel@tonic-gate #endif /* defined(_INT64_TYPE) */ 3940Sstevel@tonic-gate 3950Sstevel@tonic-gate 3960Sstevel@tonic-gate extern int atomic_set_long_excl(); 3970Sstevel@tonic-gate extern int atomic_clear_long_excl(); 3980Sstevel@tonic-gate 3990Sstevel@tonic-gate extern void membar_enter(); 4000Sstevel@tonic-gate extern void membar_exit(); 4010Sstevel@tonic-gate extern void membar_producer(); 4020Sstevel@tonic-gate extern void membar_consumer(); 4030Sstevel@tonic-gate 4040Sstevel@tonic-gate #endif 4050Sstevel@tonic-gate 4060Sstevel@tonic-gate #if defined(_KERNEL) 4070Sstevel@tonic-gate 4080Sstevel@tonic-gate #if defined(_LP64) || defined(_ILP32) 4090Sstevel@tonic-gate #define atomic_add_ip atomic_add_long 4100Sstevel@tonic-gate #define atomic_add_ip_nv atomic_add_long_nv 4110Sstevel@tonic-gate #define casip atomic_cas_ulong 4120Sstevel@tonic-gate #endif 4130Sstevel@tonic-gate 4140Sstevel@tonic-gate #if defined(__sparc) 4150Sstevel@tonic-gate extern uint8_t ldstub(uint8_t *); 4160Sstevel@tonic-gate #endif 4170Sstevel@tonic-gate 4180Sstevel@tonic-gate /* 4190Sstevel@tonic-gate * Legacy kernel interfaces; they will go away (eventually). 4200Sstevel@tonic-gate */ 4210Sstevel@tonic-gate extern uint8_t cas8(uint8_t *, uint8_t, uint8_t); 4220Sstevel@tonic-gate extern uint32_t cas32(uint32_t *, uint32_t, uint32_t); 4230Sstevel@tonic-gate extern uint64_t cas64(uint64_t *, uint64_t, uint64_t); 4240Sstevel@tonic-gate extern ulong_t caslong(ulong_t *, ulong_t, ulong_t); 4250Sstevel@tonic-gate extern void *casptr(void *, void *, void *); 4260Sstevel@tonic-gate extern void atomic_and_long(ulong_t *, ulong_t); 4270Sstevel@tonic-gate extern void atomic_or_long(ulong_t *, ulong_t); 4280Sstevel@tonic-gate #if defined(__sparc) 4290Sstevel@tonic-gate extern uint32_t swapl(uint32_t *, uint32_t); 4300Sstevel@tonic-gate #endif 4310Sstevel@tonic-gate 4320Sstevel@tonic-gate #endif /* _KERNEL */ 4330Sstevel@tonic-gate 4340Sstevel@tonic-gate #ifdef __cplusplus 4350Sstevel@tonic-gate } 4360Sstevel@tonic-gate #endif 4370Sstevel@tonic-gate 4380Sstevel@tonic-gate #endif /* _SYS_ATOMIC_H */ 439