1*0Sstevel@tonic-gate /* 2*0Sstevel@tonic-gate * CDDL HEADER START 3*0Sstevel@tonic-gate * 4*0Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*0Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*0Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*0Sstevel@tonic-gate * with the License. 8*0Sstevel@tonic-gate * 9*0Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*0Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*0Sstevel@tonic-gate * See the License for the specific language governing permissions 12*0Sstevel@tonic-gate * and limitations under the License. 13*0Sstevel@tonic-gate * 14*0Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*0Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*0Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*0Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*0Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*0Sstevel@tonic-gate * 20*0Sstevel@tonic-gate * CDDL HEADER END 21*0Sstevel@tonic-gate */ 22*0Sstevel@tonic-gate /* 23*0Sstevel@tonic-gate * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 24*0Sstevel@tonic-gate * Use is subject to license terms. 25*0Sstevel@tonic-gate */ 26*0Sstevel@tonic-gate 27*0Sstevel@tonic-gate #ifndef _SYS_ATOMIC_H 28*0Sstevel@tonic-gate #define _SYS_ATOMIC_H 29*0Sstevel@tonic-gate 30*0Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 31*0Sstevel@tonic-gate 32*0Sstevel@tonic-gate #include <sys/types.h> 33*0Sstevel@tonic-gate #include <sys/inttypes.h> 34*0Sstevel@tonic-gate 35*0Sstevel@tonic-gate #ifdef __cplusplus 36*0Sstevel@tonic-gate extern "C" { 37*0Sstevel@tonic-gate #endif 38*0Sstevel@tonic-gate 39*0Sstevel@tonic-gate #if defined(_KERNEL) && defined(__GNUC__) && defined(_ASM_INLINES) 40*0Sstevel@tonic-gate #include <asm/atomic.h> 41*0Sstevel@tonic-gate #endif 42*0Sstevel@tonic-gate 43*0Sstevel@tonic-gate #if defined(_KERNEL) || defined(__STDC__) 44*0Sstevel@tonic-gate /* 45*0Sstevel@tonic-gate * Increment target. 46*0Sstevel@tonic-gate */ 47*0Sstevel@tonic-gate extern void atomic_inc_8(volatile uint8_t *); 48*0Sstevel@tonic-gate extern void atomic_inc_uchar(volatile uchar_t *); 49*0Sstevel@tonic-gate extern void atomic_inc_16(volatile uint16_t *); 50*0Sstevel@tonic-gate extern void atomic_inc_ushort(volatile ushort_t *); 51*0Sstevel@tonic-gate extern void atomic_inc_32(volatile uint32_t *); 52*0Sstevel@tonic-gate extern void atomic_inc_uint(volatile uint_t *); 53*0Sstevel@tonic-gate extern void atomic_inc_ulong(volatile ulong_t *); 54*0Sstevel@tonic-gate #if defined(_KERNEL) || defined(_INT64_TYPE) 55*0Sstevel@tonic-gate extern void atomic_inc_64(volatile uint64_t *); 56*0Sstevel@tonic-gate #endif 57*0Sstevel@tonic-gate 58*0Sstevel@tonic-gate /* 59*0Sstevel@tonic-gate * Decrement target 60*0Sstevel@tonic-gate */ 61*0Sstevel@tonic-gate extern void atomic_dec_8(volatile uint8_t *); 62*0Sstevel@tonic-gate extern void atomic_dec_uchar(volatile uchar_t *); 63*0Sstevel@tonic-gate extern void atomic_dec_16(volatile uint16_t *); 64*0Sstevel@tonic-gate extern void atomic_dec_ushort(volatile ushort_t *); 65*0Sstevel@tonic-gate extern void atomic_dec_32(volatile uint32_t *); 66*0Sstevel@tonic-gate extern void atomic_dec_uint(volatile uint_t *); 67*0Sstevel@tonic-gate extern void atomic_dec_ulong(volatile ulong_t *); 68*0Sstevel@tonic-gate #if defined(_KERNEL) || defined(_INT64_TYPE) 69*0Sstevel@tonic-gate extern void atomic_dec_64(volatile uint64_t *); 70*0Sstevel@tonic-gate #endif 71*0Sstevel@tonic-gate 72*0Sstevel@tonic-gate /* 73*0Sstevel@tonic-gate * Add delta to target 74*0Sstevel@tonic-gate */ 75*0Sstevel@tonic-gate extern void atomic_add_8(volatile uint8_t *, int8_t); 76*0Sstevel@tonic-gate extern void atomic_add_char(volatile uchar_t *, signed char); 77*0Sstevel@tonic-gate extern void atomic_add_16(volatile uint16_t *, int16_t); 78*0Sstevel@tonic-gate extern void atomic_add_short(volatile ushort_t *, short); 79*0Sstevel@tonic-gate extern void atomic_add_32(volatile uint32_t *, int32_t); 80*0Sstevel@tonic-gate extern void atomic_add_int(volatile uint_t *, int); 81*0Sstevel@tonic-gate extern void atomic_add_ptr(volatile void *, ssize_t); 82*0Sstevel@tonic-gate extern void atomic_add_long(volatile ulong_t *, long); 83*0Sstevel@tonic-gate #if defined(_KERNEL) || defined(_INT64_TYPE) 84*0Sstevel@tonic-gate extern void atomic_add_64(volatile uint64_t *, int64_t); 85*0Sstevel@tonic-gate #endif 86*0Sstevel@tonic-gate 87*0Sstevel@tonic-gate /* 88*0Sstevel@tonic-gate * logical OR bits with target 89*0Sstevel@tonic-gate */ 90*0Sstevel@tonic-gate extern void atomic_or_8(volatile uint8_t *, uint8_t); 91*0Sstevel@tonic-gate extern void atomic_or_uchar(volatile uchar_t *, uchar_t); 92*0Sstevel@tonic-gate extern void atomic_or_16(volatile uint16_t *, uint16_t); 93*0Sstevel@tonic-gate extern void atomic_or_ushort(volatile ushort_t *, ushort_t); 94*0Sstevel@tonic-gate extern void atomic_or_32(volatile uint32_t *, uint32_t); 95*0Sstevel@tonic-gate extern void atomic_or_uint(volatile uint_t *, uint_t); 96*0Sstevel@tonic-gate extern void atomic_or_ulong(volatile ulong_t *, ulong_t); 97*0Sstevel@tonic-gate #if defined(_KERNEL) || defined(_INT64_TYPE) 98*0Sstevel@tonic-gate extern void atomic_or_64(volatile uint64_t *, uint64_t); 99*0Sstevel@tonic-gate #endif 100*0Sstevel@tonic-gate 101*0Sstevel@tonic-gate /* 102*0Sstevel@tonic-gate * logical AND bits with target 103*0Sstevel@tonic-gate */ 104*0Sstevel@tonic-gate extern void atomic_and_8(volatile uint8_t *, uint8_t); 105*0Sstevel@tonic-gate extern void atomic_and_uchar(volatile uchar_t *, uchar_t); 106*0Sstevel@tonic-gate extern void atomic_and_16(volatile uint16_t *, uint16_t); 107*0Sstevel@tonic-gate extern void atomic_and_ushort(volatile ushort_t *, ushort_t); 108*0Sstevel@tonic-gate extern void atomic_and_32(volatile uint32_t *, uint32_t); 109*0Sstevel@tonic-gate extern void atomic_and_uint(volatile uint_t *, uint_t); 110*0Sstevel@tonic-gate extern void atomic_and_ulong(volatile ulong_t *, ulong_t); 111*0Sstevel@tonic-gate #if defined(_KERNEL) || defined(_INT64_TYPE) 112*0Sstevel@tonic-gate extern void atomic_and_64(volatile uint64_t *, uint64_t); 113*0Sstevel@tonic-gate #endif 114*0Sstevel@tonic-gate 115*0Sstevel@tonic-gate /* 116*0Sstevel@tonic-gate * As above, but return the new value. Note that these _nv() variants are 117*0Sstevel@tonic-gate * substantially more expensive on some platforms than the no-return-value 118*0Sstevel@tonic-gate * versions above, so don't use them unless you really need to know the 119*0Sstevel@tonic-gate * new value *atomically* (e.g. when decrementing a reference count and 120*0Sstevel@tonic-gate * checking whether it went to zero). 121*0Sstevel@tonic-gate */ 122*0Sstevel@tonic-gate 123*0Sstevel@tonic-gate /* 124*0Sstevel@tonic-gate * Increment target and return new value. 125*0Sstevel@tonic-gate */ 126*0Sstevel@tonic-gate extern uint8_t atomic_inc_8_nv(volatile uint8_t *); 127*0Sstevel@tonic-gate extern uchar_t atomic_inc_uchar_nv(volatile uchar_t *); 128*0Sstevel@tonic-gate extern uint16_t atomic_inc_16_nv(volatile uint16_t *); 129*0Sstevel@tonic-gate extern ushort_t atomic_inc_ushort_nv(volatile ushort_t *); 130*0Sstevel@tonic-gate extern uint32_t atomic_inc_32_nv(volatile uint32_t *); 131*0Sstevel@tonic-gate extern uint_t atomic_inc_uint_nv(volatile uint_t *); 132*0Sstevel@tonic-gate extern ulong_t atomic_inc_ulong_nv(volatile ulong_t *); 133*0Sstevel@tonic-gate #if defined(_KERNEL) || defined(_INT64_TYPE) 134*0Sstevel@tonic-gate extern uint64_t atomic_inc_64_nv(volatile uint64_t *); 135*0Sstevel@tonic-gate #endif 136*0Sstevel@tonic-gate 137*0Sstevel@tonic-gate /* 138*0Sstevel@tonic-gate * Decrement target and return new value. 139*0Sstevel@tonic-gate */ 140*0Sstevel@tonic-gate extern uint8_t atomic_dec_8_nv(volatile uint8_t *); 141*0Sstevel@tonic-gate extern uchar_t atomic_dec_uchar_nv(volatile uchar_t *); 142*0Sstevel@tonic-gate extern uint16_t atomic_dec_16_nv(volatile uint16_t *); 143*0Sstevel@tonic-gate extern ushort_t atomic_dec_ushort_nv(volatile ushort_t *); 144*0Sstevel@tonic-gate extern uint32_t atomic_dec_32_nv(volatile uint32_t *); 145*0Sstevel@tonic-gate extern uint_t atomic_dec_uint_nv(volatile uint_t *); 146*0Sstevel@tonic-gate extern ulong_t atomic_dec_ulong_nv(volatile ulong_t *); 147*0Sstevel@tonic-gate #if defined(_KERNEL) || defined(_INT64_TYPE) 148*0Sstevel@tonic-gate extern uint64_t atomic_dec_64_nv(volatile uint64_t *); 149*0Sstevel@tonic-gate #endif 150*0Sstevel@tonic-gate 151*0Sstevel@tonic-gate /* 152*0Sstevel@tonic-gate * Add delta to target 153*0Sstevel@tonic-gate */ 154*0Sstevel@tonic-gate extern uint8_t atomic_add_8_nv(volatile uint8_t *, int8_t); 155*0Sstevel@tonic-gate extern uchar_t atomic_add_char_nv(volatile uchar_t *, signed char); 156*0Sstevel@tonic-gate extern uint16_t atomic_add_16_nv(volatile uint16_t *, int16_t); 157*0Sstevel@tonic-gate extern ushort_t atomic_add_short_nv(volatile ushort_t *, short); 158*0Sstevel@tonic-gate extern uint32_t atomic_add_32_nv(volatile uint32_t *, int32_t); 159*0Sstevel@tonic-gate extern uint_t atomic_add_int_nv(volatile uint_t *, int); 160*0Sstevel@tonic-gate extern void *atomic_add_ptr_nv(volatile void *, ssize_t); 161*0Sstevel@tonic-gate extern ulong_t atomic_add_long_nv(volatile ulong_t *, long); 162*0Sstevel@tonic-gate #if defined(_KERNEL) || defined(_INT64_TYPE) 163*0Sstevel@tonic-gate extern uint64_t atomic_add_64_nv(volatile uint64_t *, int64_t); 164*0Sstevel@tonic-gate #endif 165*0Sstevel@tonic-gate 166*0Sstevel@tonic-gate /* 167*0Sstevel@tonic-gate * logical OR bits with target and return new value. 168*0Sstevel@tonic-gate */ 169*0Sstevel@tonic-gate extern uint8_t atomic_or_8_nv(volatile uint8_t *, uint8_t); 170*0Sstevel@tonic-gate extern uchar_t atomic_or_uchar_nv(volatile uchar_t *, uchar_t); 171*0Sstevel@tonic-gate extern uint16_t atomic_or_16_nv(volatile uint16_t *, uint16_t); 172*0Sstevel@tonic-gate extern ushort_t atomic_or_ushort_nv(volatile ushort_t *, ushort_t); 173*0Sstevel@tonic-gate extern uint32_t atomic_or_32_nv(volatile uint32_t *, uint32_t); 174*0Sstevel@tonic-gate extern uint_t atomic_or_uint_nv(volatile uint_t *, uint_t); 175*0Sstevel@tonic-gate extern ulong_t atomic_or_ulong_nv(volatile ulong_t *, ulong_t); 176*0Sstevel@tonic-gate #if defined(_KERNEL) || defined(_INT64_TYPE) 177*0Sstevel@tonic-gate extern uint64_t atomic_or_64_nv(volatile uint64_t *, uint64_t); 178*0Sstevel@tonic-gate #endif 179*0Sstevel@tonic-gate 180*0Sstevel@tonic-gate /* 181*0Sstevel@tonic-gate * logical AND bits with target and return new value. 182*0Sstevel@tonic-gate */ 183*0Sstevel@tonic-gate extern uint8_t atomic_and_8_nv(volatile uint8_t *, uint8_t); 184*0Sstevel@tonic-gate extern uchar_t atomic_and_uchar_nv(volatile uchar_t *, uchar_t); 185*0Sstevel@tonic-gate extern uint16_t atomic_and_16_nv(volatile uint16_t *, uint16_t); 186*0Sstevel@tonic-gate extern ushort_t atomic_and_ushort_nv(volatile ushort_t *, ushort_t); 187*0Sstevel@tonic-gate extern uint32_t atomic_and_32_nv(volatile uint32_t *, uint32_t); 188*0Sstevel@tonic-gate extern uint_t atomic_and_uint_nv(volatile uint_t *, uint_t); 189*0Sstevel@tonic-gate extern ulong_t atomic_and_ulong_nv(volatile ulong_t *, ulong_t); 190*0Sstevel@tonic-gate #if defined(_KERNEL) || defined(_INT64_TYPE) 191*0Sstevel@tonic-gate extern uint64_t atomic_and_64_nv(volatile uint64_t *, uint64_t); 192*0Sstevel@tonic-gate #endif 193*0Sstevel@tonic-gate 194*0Sstevel@tonic-gate /* 195*0Sstevel@tonic-gate * If *arg1 == arg2, set *arg1 = arg3; return old value 196*0Sstevel@tonic-gate */ 197*0Sstevel@tonic-gate extern uint8_t atomic_cas_8(volatile uint8_t *, uint8_t, uint8_t); 198*0Sstevel@tonic-gate extern uchar_t atomic_cas_uchar(volatile uchar_t *, uchar_t, uchar_t); 199*0Sstevel@tonic-gate extern uint16_t atomic_cas_16(volatile uint16_t *, uint16_t, uint16_t); 200*0Sstevel@tonic-gate extern ushort_t atomic_cas_ushort(volatile ushort_t *, ushort_t, ushort_t); 201*0Sstevel@tonic-gate extern uint32_t atomic_cas_32(volatile uint32_t *, uint32_t, uint32_t); 202*0Sstevel@tonic-gate extern uint_t atomic_cas_uint(volatile uint_t *, uint_t, uint_t); 203*0Sstevel@tonic-gate extern void *atomic_cas_ptr(volatile void *, void *, void *); 204*0Sstevel@tonic-gate extern ulong_t atomic_cas_ulong(volatile ulong_t *, ulong_t, ulong_t); 205*0Sstevel@tonic-gate #if defined(_KERNEL) || defined(_INT64_TYPE) 206*0Sstevel@tonic-gate extern uint64_t atomic_cas_64(volatile uint64_t *, uint64_t, uint64_t); 207*0Sstevel@tonic-gate #endif 208*0Sstevel@tonic-gate 209*0Sstevel@tonic-gate /* 210*0Sstevel@tonic-gate * Swap target and return old value 211*0Sstevel@tonic-gate */ 212*0Sstevel@tonic-gate extern uint8_t atomic_swap_8(volatile uint8_t *, uint8_t); 213*0Sstevel@tonic-gate extern uchar_t atomic_swap_uchar(volatile uchar_t *, uchar_t); 214*0Sstevel@tonic-gate extern uint16_t atomic_swap_16(volatile uint16_t *, uint16_t); 215*0Sstevel@tonic-gate extern ushort_t atomic_swap_ushort(volatile ushort_t *, ushort_t); 216*0Sstevel@tonic-gate extern uint32_t atomic_swap_32(volatile uint32_t *, uint32_t); 217*0Sstevel@tonic-gate extern uint_t atomic_swap_uint(volatile uint_t *, uint_t); 218*0Sstevel@tonic-gate extern void *atomic_swap_ptr(volatile void *, void *); 219*0Sstevel@tonic-gate extern ulong_t atomic_swap_ulong(volatile ulong_t *, ulong_t); 220*0Sstevel@tonic-gate #if defined(_KERNEL) || defined(_INT64_TYPE) 221*0Sstevel@tonic-gate extern uint64_t atomic_swap_64(volatile uint64_t *, uint64_t); 222*0Sstevel@tonic-gate #endif 223*0Sstevel@tonic-gate 224*0Sstevel@tonic-gate /* 225*0Sstevel@tonic-gate * Perform an exclusive atomic bit set/clear on a target. 226*0Sstevel@tonic-gate * Returns 0 if bit was sucessfully set/cleared, or -1 227*0Sstevel@tonic-gate * if the bit was already set/cleared. 228*0Sstevel@tonic-gate */ 229*0Sstevel@tonic-gate extern int atomic_set_long_excl(volatile ulong_t *, uint_t); 230*0Sstevel@tonic-gate extern int atomic_clear_long_excl(volatile ulong_t *, uint_t); 231*0Sstevel@tonic-gate 232*0Sstevel@tonic-gate /* 233*0Sstevel@tonic-gate * Generic memory barrier used during lock entry, placed after the 234*0Sstevel@tonic-gate * memory operation that acquires the lock to guarantee that the lock 235*0Sstevel@tonic-gate * protects its data. No stores from after the memory barrier will 236*0Sstevel@tonic-gate * reach visibility, and no loads from after the barrier will be 237*0Sstevel@tonic-gate * resolved, before the lock acquisition reaches global visibility. 238*0Sstevel@tonic-gate */ 239*0Sstevel@tonic-gate extern void membar_enter(void); 240*0Sstevel@tonic-gate 241*0Sstevel@tonic-gate /* 242*0Sstevel@tonic-gate * Generic memory barrier used during lock exit, placed before the 243*0Sstevel@tonic-gate * memory operation that releases the lock to guarantee that the lock 244*0Sstevel@tonic-gate * protects its data. All loads and stores issued before the barrier 245*0Sstevel@tonic-gate * will be resolved before the subsequent lock update reaches visibility. 246*0Sstevel@tonic-gate */ 247*0Sstevel@tonic-gate extern void membar_exit(void); 248*0Sstevel@tonic-gate 249*0Sstevel@tonic-gate /* 250*0Sstevel@tonic-gate * Arrange that all stores issued before this point in the code reach 251*0Sstevel@tonic-gate * global visibility before any stores that follow; useful in producer 252*0Sstevel@tonic-gate * modules that update a data item, then set a flag that it is available. 253*0Sstevel@tonic-gate * The memory barrier guarantees that the available flag is not visible 254*0Sstevel@tonic-gate * earlier than the updated data, i.e. it imposes store ordering. 255*0Sstevel@tonic-gate */ 256*0Sstevel@tonic-gate extern void membar_producer(void); 257*0Sstevel@tonic-gate 258*0Sstevel@tonic-gate /* 259*0Sstevel@tonic-gate * Arrange that all loads issued before this point in the code are 260*0Sstevel@tonic-gate * completed before any subsequent loads; useful in consumer modules 261*0Sstevel@tonic-gate * that check to see if data is available and read the data. 262*0Sstevel@tonic-gate * The memory barrier guarantees that the data is not sampled until 263*0Sstevel@tonic-gate * after the available flag has been seen, i.e. it imposes load ordering. 264*0Sstevel@tonic-gate */ 265*0Sstevel@tonic-gate extern void membar_consumer(void); 266*0Sstevel@tonic-gate #endif 267*0Sstevel@tonic-gate 268*0Sstevel@tonic-gate #if !defined(_KERNEL) && !defined(__STDC__) 269*0Sstevel@tonic-gate extern void atomic_inc_8(); 270*0Sstevel@tonic-gate extern void atomic_inc_uchar(); 271*0Sstevel@tonic-gate extern void atomic_inc_16(); 272*0Sstevel@tonic-gate extern void atomic_inc_ushort(); 273*0Sstevel@tonic-gate extern void atomic_inc_32(); 274*0Sstevel@tonic-gate extern void atomic_inc_uint(); 275*0Sstevel@tonic-gate extern void atomic_inc_ulong(); 276*0Sstevel@tonic-gate #if defined(_INT64_TYPE) 277*0Sstevel@tonic-gate extern void atomic_inc_64(); 278*0Sstevel@tonic-gate #endif /* defined(_INT64_TYPE) */ 279*0Sstevel@tonic-gate extern void atomic_dec_8(); 280*0Sstevel@tonic-gate extern void atomic_dec_uchar(); 281*0Sstevel@tonic-gate extern void atomic_dec_16(); 282*0Sstevel@tonic-gate extern void atomic_dec_ushort(); 283*0Sstevel@tonic-gate extern void atomic_dec_32(); 284*0Sstevel@tonic-gate extern void atomic_dec_uint(); 285*0Sstevel@tonic-gate extern void atomic_dec_ulong(); 286*0Sstevel@tonic-gate #if defined(_INT64_TYPE) 287*0Sstevel@tonic-gate extern void atomic_dec_64(); 288*0Sstevel@tonic-gate #endif /* defined(_INT64_TYPE) */ 289*0Sstevel@tonic-gate extern void atomic_add_8(); 290*0Sstevel@tonic-gate extern void atomic_add_char(); 291*0Sstevel@tonic-gate extern void atomic_add_16(); 292*0Sstevel@tonic-gate extern void atomic_add_short(); 293*0Sstevel@tonic-gate extern void atomic_add_32(); 294*0Sstevel@tonic-gate extern void atomic_add_int(); 295*0Sstevel@tonic-gate extern void atomic_add_ptr(); 296*0Sstevel@tonic-gate extern void atomic_add_long(); 297*0Sstevel@tonic-gate #if defined(_INT64_TYPE) 298*0Sstevel@tonic-gate extern void atomic_add_64(); 299*0Sstevel@tonic-gate #endif /* defined(_INT64_TYPE) */ 300*0Sstevel@tonic-gate extern void atomic_or_8(); 301*0Sstevel@tonic-gate extern void atomic_or_uchar(); 302*0Sstevel@tonic-gate extern void atomic_or_16(); 303*0Sstevel@tonic-gate extern void atomic_or_ushort(); 304*0Sstevel@tonic-gate extern void atomic_or_32(); 305*0Sstevel@tonic-gate extern void atomic_or_uint(); 306*0Sstevel@tonic-gate extern void atomic_or_ulong(); 307*0Sstevel@tonic-gate #if defined(_INT64_TYPE) 308*0Sstevel@tonic-gate extern void atomic_or_64(); 309*0Sstevel@tonic-gate #endif /* defined(_INT64_TYPE) */ 310*0Sstevel@tonic-gate extern void atomic_and_8(); 311*0Sstevel@tonic-gate extern void atomic_and_uchar(); 312*0Sstevel@tonic-gate extern void atomic_and_16(); 313*0Sstevel@tonic-gate extern void atomic_and_ushort(); 314*0Sstevel@tonic-gate extern void atomic_and_32(); 315*0Sstevel@tonic-gate extern void atomic_and_uint(); 316*0Sstevel@tonic-gate extern void atomic_and_ulong(); 317*0Sstevel@tonic-gate #if defined(_INT64_TYPE) 318*0Sstevel@tonic-gate extern void atomic_and_64(); 319*0Sstevel@tonic-gate #endif /* defined(_INT64_TYPE) */ 320*0Sstevel@tonic-gate extern uint8_t atomic_inc_8_nv(); 321*0Sstevel@tonic-gate extern uchar_t atomic_inc_uchar_nv(); 322*0Sstevel@tonic-gate extern uint16_t atomic_inc_16_nv(); 323*0Sstevel@tonic-gate extern ushort_t atomic_inc_ushort_nv(); 324*0Sstevel@tonic-gate extern uint32_t atomic_inc_32_nv(); 325*0Sstevel@tonic-gate extern uint_t atomic_inc_uint_nv(); 326*0Sstevel@tonic-gate extern ulong_t atomic_inc_ulong_nv(); 327*0Sstevel@tonic-gate #if defined(_INT64_TYPE) 328*0Sstevel@tonic-gate extern uint64_t atomic_inc_64_nv(); 329*0Sstevel@tonic-gate #endif /* defined(_INT64_TYPE) */ 330*0Sstevel@tonic-gate extern uint8_t atomic_dec_8_nv(); 331*0Sstevel@tonic-gate extern uchar_t atomic_dec_uchar_nv(); 332*0Sstevel@tonic-gate extern uint16_t atomic_dec_16_nv(); 333*0Sstevel@tonic-gate extern ushort_t atomic_dec_ushort_nv(); 334*0Sstevel@tonic-gate extern uint32_t atomic_dec_32_nv(); 335*0Sstevel@tonic-gate extern uint_t atomic_dec_uint_nv(); 336*0Sstevel@tonic-gate extern ulong_t atomic_dec_ulong_nv(); 337*0Sstevel@tonic-gate #if defined(_INT64_TYPE) 338*0Sstevel@tonic-gate extern uint64_t atomic_dec_64_nv(); 339*0Sstevel@tonic-gate #endif /* defined(_INT64_TYPE) */ 340*0Sstevel@tonic-gate extern uint8_t atomic_add_8_nv(); 341*0Sstevel@tonic-gate extern uchar_t atomic_add_char_nv(); 342*0Sstevel@tonic-gate extern uint16_t atomic_add_16_nv(); 343*0Sstevel@tonic-gate extern ushort_t atomic_add_short_nv(); 344*0Sstevel@tonic-gate extern uint32_t atomic_add_32_nv(); 345*0Sstevel@tonic-gate extern uint_t atomic_add_int_nv(); 346*0Sstevel@tonic-gate extern void *atomic_add_ptr_nv(); 347*0Sstevel@tonic-gate extern ulong_t atomic_add_long_nv(); 348*0Sstevel@tonic-gate #if defined(_INT64_TYPE) 349*0Sstevel@tonic-gate extern uint64_t atomic_add_64_nv(); 350*0Sstevel@tonic-gate #endif /* defined(_INT64_TYPE) */ 351*0Sstevel@tonic-gate extern uint8_t atomic_or_8_nv(); 352*0Sstevel@tonic-gate extern uchar_t atomic_or_uchar_nv(); 353*0Sstevel@tonic-gate extern uint16_t atomic_or_16_nv(); 354*0Sstevel@tonic-gate extern ushort_t atomic_or_ushort_nv(); 355*0Sstevel@tonic-gate extern uint32_t atomic_or_32_nv(); 356*0Sstevel@tonic-gate extern uint_t atomic_or_uint_nv(); 357*0Sstevel@tonic-gate extern ulong_t atomic_or_ulong_nv(); 358*0Sstevel@tonic-gate #if defined(_INT64_TYPE) 359*0Sstevel@tonic-gate extern uint64_t atomic_or_64_nv(); 360*0Sstevel@tonic-gate #endif /* defined(_INT64_TYPE) */ 361*0Sstevel@tonic-gate extern uint8_t atomic_and_8_nv(); 362*0Sstevel@tonic-gate extern uchar_t atomic_and_uchar_nv(); 363*0Sstevel@tonic-gate extern uint16_t atomic_and_16_nv(); 364*0Sstevel@tonic-gate extern ushort_t atomic_and_ushort_nv(); 365*0Sstevel@tonic-gate extern uint32_t atomic_and_32_nv(); 366*0Sstevel@tonic-gate extern uint_t atomic_and_uint_nv(); 367*0Sstevel@tonic-gate extern ulong_t atomic_and_ulong_nv(); 368*0Sstevel@tonic-gate #if defined(_INT64_TYPE) 369*0Sstevel@tonic-gate extern uint64_t atomic_and_64_nv(); 370*0Sstevel@tonic-gate #endif /* defined(_INT64_TYPE) */ 371*0Sstevel@tonic-gate extern uint8_t atomic_cas_8(); 372*0Sstevel@tonic-gate extern uchar_t atomic_cas_uchar(); 373*0Sstevel@tonic-gate extern uint16_t atomic_cas_16(); 374*0Sstevel@tonic-gate extern ushort_t atomic_cas_ushort(); 375*0Sstevel@tonic-gate extern uint32_t atomic_cas_32(); 376*0Sstevel@tonic-gate extern uint_t atomic_cas_uint(); 377*0Sstevel@tonic-gate extern void *atomic_cas_ptr(); 378*0Sstevel@tonic-gate extern ulong_t atomic_cas_ulong(); 379*0Sstevel@tonic-gate #if defined(_INT64_TYPE) 380*0Sstevel@tonic-gate extern uint64_t atomic_cas_64(); 381*0Sstevel@tonic-gate #endif /* defined(_INT64_TYPE) */ 382*0Sstevel@tonic-gate extern uint8_t atomic_swap_8(); 383*0Sstevel@tonic-gate extern uchar_t atomic_swap_uchar(); 384*0Sstevel@tonic-gate extern uint16_t atomic_swap_16(); 385*0Sstevel@tonic-gate extern ushort_t atomic_swap_ushort(); 386*0Sstevel@tonic-gate extern uint32_t atomic_swap_32(); 387*0Sstevel@tonic-gate extern uint_t atomic_swap_uint(); 388*0Sstevel@tonic-gate extern void *atomic_swap_ptr(); 389*0Sstevel@tonic-gate extern ulong_t atomic_swap_ulong(); 390*0Sstevel@tonic-gate #if defined(_INT64_TYPE) 391*0Sstevel@tonic-gate extern uint64_t atomic_swap_64(); 392*0Sstevel@tonic-gate #endif /* defined(_INT64_TYPE) */ 393*0Sstevel@tonic-gate 394*0Sstevel@tonic-gate 395*0Sstevel@tonic-gate extern int atomic_set_long_excl(); 396*0Sstevel@tonic-gate extern int atomic_clear_long_excl(); 397*0Sstevel@tonic-gate 398*0Sstevel@tonic-gate extern void membar_enter(); 399*0Sstevel@tonic-gate extern void membar_exit(); 400*0Sstevel@tonic-gate extern void membar_producer(); 401*0Sstevel@tonic-gate extern void membar_consumer(); 402*0Sstevel@tonic-gate 403*0Sstevel@tonic-gate #endif 404*0Sstevel@tonic-gate 405*0Sstevel@tonic-gate #if defined(_KERNEL) 406*0Sstevel@tonic-gate 407*0Sstevel@tonic-gate #if defined(_LP64) || defined(_ILP32) 408*0Sstevel@tonic-gate #define atomic_add_ip atomic_add_long 409*0Sstevel@tonic-gate #define atomic_add_ip_nv atomic_add_long_nv 410*0Sstevel@tonic-gate #define casip atomic_cas_ulong 411*0Sstevel@tonic-gate #endif 412*0Sstevel@tonic-gate 413*0Sstevel@tonic-gate #if defined(__sparc) 414*0Sstevel@tonic-gate extern uint8_t ldstub(uint8_t *); 415*0Sstevel@tonic-gate #endif 416*0Sstevel@tonic-gate 417*0Sstevel@tonic-gate /* 418*0Sstevel@tonic-gate * Legacy kernel interfaces; they will go away (eventually). 419*0Sstevel@tonic-gate */ 420*0Sstevel@tonic-gate extern uint8_t cas8(uint8_t *, uint8_t, uint8_t); 421*0Sstevel@tonic-gate extern uint32_t cas32(uint32_t *, uint32_t, uint32_t); 422*0Sstevel@tonic-gate extern uint64_t cas64(uint64_t *, uint64_t, uint64_t); 423*0Sstevel@tonic-gate extern ulong_t caslong(ulong_t *, ulong_t, ulong_t); 424*0Sstevel@tonic-gate extern void *casptr(void *, void *, void *); 425*0Sstevel@tonic-gate extern void atomic_and_long(ulong_t *, ulong_t); 426*0Sstevel@tonic-gate extern void atomic_or_long(ulong_t *, ulong_t); 427*0Sstevel@tonic-gate #if defined(__sparc) 428*0Sstevel@tonic-gate extern uint32_t swapl(uint32_t *, uint32_t); 429*0Sstevel@tonic-gate #endif 430*0Sstevel@tonic-gate 431*0Sstevel@tonic-gate #endif /* _KERNEL */ 432*0Sstevel@tonic-gate 433*0Sstevel@tonic-gate #ifdef __cplusplus 434*0Sstevel@tonic-gate } 435*0Sstevel@tonic-gate #endif 436*0Sstevel@tonic-gate 437*0Sstevel@tonic-gate #endif /* _SYS_ATOMIC_H */ 438