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 5*2b616c6cSwesolows * Common Development and Distribution License (the "License"). 6*2b616c6cSwesolows * 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*2b616c6cSwesolows 227c478bd9Sstevel@tonic-gate /* 237c478bd9Sstevel@tonic-gate * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 247c478bd9Sstevel@tonic-gate * Use is subject to license terms. 257c478bd9Sstevel@tonic-gate */ 267c478bd9Sstevel@tonic-gate 277c478bd9Sstevel@tonic-gate #ifndef _SYS_ATOMIC_H 287c478bd9Sstevel@tonic-gate #define _SYS_ATOMIC_H 297c478bd9Sstevel@tonic-gate 307c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 317c478bd9Sstevel@tonic-gate 327c478bd9Sstevel@tonic-gate #include <sys/types.h> 337c478bd9Sstevel@tonic-gate #include <sys/inttypes.h> 347c478bd9Sstevel@tonic-gate 357c478bd9Sstevel@tonic-gate #ifdef __cplusplus 367c478bd9Sstevel@tonic-gate extern "C" { 377c478bd9Sstevel@tonic-gate #endif 387c478bd9Sstevel@tonic-gate 39*2b616c6cSwesolows #if defined(_KERNEL) && defined(__GNUC__) && defined(_ASM_INLINES) && \ 40*2b616c6cSwesolows (defined(__i386) || defined(__amd64)) 417c478bd9Sstevel@tonic-gate #include <asm/atomic.h> 427c478bd9Sstevel@tonic-gate #endif 437c478bd9Sstevel@tonic-gate 447c478bd9Sstevel@tonic-gate #if defined(_KERNEL) || defined(__STDC__) 457c478bd9Sstevel@tonic-gate /* 467c478bd9Sstevel@tonic-gate * Increment target. 477c478bd9Sstevel@tonic-gate */ 487c478bd9Sstevel@tonic-gate extern void atomic_inc_8(volatile uint8_t *); 497c478bd9Sstevel@tonic-gate extern void atomic_inc_uchar(volatile uchar_t *); 507c478bd9Sstevel@tonic-gate extern void atomic_inc_16(volatile uint16_t *); 517c478bd9Sstevel@tonic-gate extern void atomic_inc_ushort(volatile ushort_t *); 527c478bd9Sstevel@tonic-gate extern void atomic_inc_32(volatile uint32_t *); 537c478bd9Sstevel@tonic-gate extern void atomic_inc_uint(volatile uint_t *); 547c478bd9Sstevel@tonic-gate extern void atomic_inc_ulong(volatile ulong_t *); 557c478bd9Sstevel@tonic-gate #if defined(_KERNEL) || defined(_INT64_TYPE) 567c478bd9Sstevel@tonic-gate extern void atomic_inc_64(volatile uint64_t *); 577c478bd9Sstevel@tonic-gate #endif 587c478bd9Sstevel@tonic-gate 597c478bd9Sstevel@tonic-gate /* 607c478bd9Sstevel@tonic-gate * Decrement target 617c478bd9Sstevel@tonic-gate */ 627c478bd9Sstevel@tonic-gate extern void atomic_dec_8(volatile uint8_t *); 637c478bd9Sstevel@tonic-gate extern void atomic_dec_uchar(volatile uchar_t *); 647c478bd9Sstevel@tonic-gate extern void atomic_dec_16(volatile uint16_t *); 657c478bd9Sstevel@tonic-gate extern void atomic_dec_ushort(volatile ushort_t *); 667c478bd9Sstevel@tonic-gate extern void atomic_dec_32(volatile uint32_t *); 677c478bd9Sstevel@tonic-gate extern void atomic_dec_uint(volatile uint_t *); 687c478bd9Sstevel@tonic-gate extern void atomic_dec_ulong(volatile ulong_t *); 697c478bd9Sstevel@tonic-gate #if defined(_KERNEL) || defined(_INT64_TYPE) 707c478bd9Sstevel@tonic-gate extern void atomic_dec_64(volatile uint64_t *); 717c478bd9Sstevel@tonic-gate #endif 727c478bd9Sstevel@tonic-gate 737c478bd9Sstevel@tonic-gate /* 747c478bd9Sstevel@tonic-gate * Add delta to target 757c478bd9Sstevel@tonic-gate */ 767c478bd9Sstevel@tonic-gate extern void atomic_add_8(volatile uint8_t *, int8_t); 777c478bd9Sstevel@tonic-gate extern void atomic_add_char(volatile uchar_t *, signed char); 787c478bd9Sstevel@tonic-gate extern void atomic_add_16(volatile uint16_t *, int16_t); 797c478bd9Sstevel@tonic-gate extern void atomic_add_short(volatile ushort_t *, short); 807c478bd9Sstevel@tonic-gate extern void atomic_add_32(volatile uint32_t *, int32_t); 817c478bd9Sstevel@tonic-gate extern void atomic_add_int(volatile uint_t *, int); 827c478bd9Sstevel@tonic-gate extern void atomic_add_ptr(volatile void *, ssize_t); 837c478bd9Sstevel@tonic-gate extern void atomic_add_long(volatile ulong_t *, long); 847c478bd9Sstevel@tonic-gate #if defined(_KERNEL) || defined(_INT64_TYPE) 857c478bd9Sstevel@tonic-gate extern void atomic_add_64(volatile uint64_t *, int64_t); 867c478bd9Sstevel@tonic-gate #endif 877c478bd9Sstevel@tonic-gate 887c478bd9Sstevel@tonic-gate /* 897c478bd9Sstevel@tonic-gate * logical OR bits with target 907c478bd9Sstevel@tonic-gate */ 917c478bd9Sstevel@tonic-gate extern void atomic_or_8(volatile uint8_t *, uint8_t); 927c478bd9Sstevel@tonic-gate extern void atomic_or_uchar(volatile uchar_t *, uchar_t); 937c478bd9Sstevel@tonic-gate extern void atomic_or_16(volatile uint16_t *, uint16_t); 947c478bd9Sstevel@tonic-gate extern void atomic_or_ushort(volatile ushort_t *, ushort_t); 957c478bd9Sstevel@tonic-gate extern void atomic_or_32(volatile uint32_t *, uint32_t); 967c478bd9Sstevel@tonic-gate extern void atomic_or_uint(volatile uint_t *, uint_t); 977c478bd9Sstevel@tonic-gate extern void atomic_or_ulong(volatile ulong_t *, ulong_t); 987c478bd9Sstevel@tonic-gate #if defined(_KERNEL) || defined(_INT64_TYPE) 997c478bd9Sstevel@tonic-gate extern void atomic_or_64(volatile uint64_t *, uint64_t); 1007c478bd9Sstevel@tonic-gate #endif 1017c478bd9Sstevel@tonic-gate 1027c478bd9Sstevel@tonic-gate /* 1037c478bd9Sstevel@tonic-gate * logical AND bits with target 1047c478bd9Sstevel@tonic-gate */ 1057c478bd9Sstevel@tonic-gate extern void atomic_and_8(volatile uint8_t *, uint8_t); 1067c478bd9Sstevel@tonic-gate extern void atomic_and_uchar(volatile uchar_t *, uchar_t); 1077c478bd9Sstevel@tonic-gate extern void atomic_and_16(volatile uint16_t *, uint16_t); 1087c478bd9Sstevel@tonic-gate extern void atomic_and_ushort(volatile ushort_t *, ushort_t); 1097c478bd9Sstevel@tonic-gate extern void atomic_and_32(volatile uint32_t *, uint32_t); 1107c478bd9Sstevel@tonic-gate extern void atomic_and_uint(volatile uint_t *, uint_t); 1117c478bd9Sstevel@tonic-gate extern void atomic_and_ulong(volatile ulong_t *, ulong_t); 1127c478bd9Sstevel@tonic-gate #if defined(_KERNEL) || defined(_INT64_TYPE) 1137c478bd9Sstevel@tonic-gate extern void atomic_and_64(volatile uint64_t *, uint64_t); 1147c478bd9Sstevel@tonic-gate #endif 1157c478bd9Sstevel@tonic-gate 1167c478bd9Sstevel@tonic-gate /* 1177c478bd9Sstevel@tonic-gate * As above, but return the new value. Note that these _nv() variants are 1187c478bd9Sstevel@tonic-gate * substantially more expensive on some platforms than the no-return-value 1197c478bd9Sstevel@tonic-gate * versions above, so don't use them unless you really need to know the 1207c478bd9Sstevel@tonic-gate * new value *atomically* (e.g. when decrementing a reference count and 1217c478bd9Sstevel@tonic-gate * checking whether it went to zero). 1227c478bd9Sstevel@tonic-gate */ 1237c478bd9Sstevel@tonic-gate 1247c478bd9Sstevel@tonic-gate /* 1257c478bd9Sstevel@tonic-gate * Increment target and return new value. 1267c478bd9Sstevel@tonic-gate */ 1277c478bd9Sstevel@tonic-gate extern uint8_t atomic_inc_8_nv(volatile uint8_t *); 1287c478bd9Sstevel@tonic-gate extern uchar_t atomic_inc_uchar_nv(volatile uchar_t *); 1297c478bd9Sstevel@tonic-gate extern uint16_t atomic_inc_16_nv(volatile uint16_t *); 1307c478bd9Sstevel@tonic-gate extern ushort_t atomic_inc_ushort_nv(volatile ushort_t *); 1317c478bd9Sstevel@tonic-gate extern uint32_t atomic_inc_32_nv(volatile uint32_t *); 1327c478bd9Sstevel@tonic-gate extern uint_t atomic_inc_uint_nv(volatile uint_t *); 1337c478bd9Sstevel@tonic-gate extern ulong_t atomic_inc_ulong_nv(volatile ulong_t *); 1347c478bd9Sstevel@tonic-gate #if defined(_KERNEL) || defined(_INT64_TYPE) 1357c478bd9Sstevel@tonic-gate extern uint64_t atomic_inc_64_nv(volatile uint64_t *); 1367c478bd9Sstevel@tonic-gate #endif 1377c478bd9Sstevel@tonic-gate 1387c478bd9Sstevel@tonic-gate /* 1397c478bd9Sstevel@tonic-gate * Decrement target and return new value. 1407c478bd9Sstevel@tonic-gate */ 1417c478bd9Sstevel@tonic-gate extern uint8_t atomic_dec_8_nv(volatile uint8_t *); 1427c478bd9Sstevel@tonic-gate extern uchar_t atomic_dec_uchar_nv(volatile uchar_t *); 1437c478bd9Sstevel@tonic-gate extern uint16_t atomic_dec_16_nv(volatile uint16_t *); 1447c478bd9Sstevel@tonic-gate extern ushort_t atomic_dec_ushort_nv(volatile ushort_t *); 1457c478bd9Sstevel@tonic-gate extern uint32_t atomic_dec_32_nv(volatile uint32_t *); 1467c478bd9Sstevel@tonic-gate extern uint_t atomic_dec_uint_nv(volatile uint_t *); 1477c478bd9Sstevel@tonic-gate extern ulong_t atomic_dec_ulong_nv(volatile ulong_t *); 1487c478bd9Sstevel@tonic-gate #if defined(_KERNEL) || defined(_INT64_TYPE) 1497c478bd9Sstevel@tonic-gate extern uint64_t atomic_dec_64_nv(volatile uint64_t *); 1507c478bd9Sstevel@tonic-gate #endif 1517c478bd9Sstevel@tonic-gate 1527c478bd9Sstevel@tonic-gate /* 1537c478bd9Sstevel@tonic-gate * Add delta to target 1547c478bd9Sstevel@tonic-gate */ 1557c478bd9Sstevel@tonic-gate extern uint8_t atomic_add_8_nv(volatile uint8_t *, int8_t); 1567c478bd9Sstevel@tonic-gate extern uchar_t atomic_add_char_nv(volatile uchar_t *, signed char); 1577c478bd9Sstevel@tonic-gate extern uint16_t atomic_add_16_nv(volatile uint16_t *, int16_t); 1587c478bd9Sstevel@tonic-gate extern ushort_t atomic_add_short_nv(volatile ushort_t *, short); 1597c478bd9Sstevel@tonic-gate extern uint32_t atomic_add_32_nv(volatile uint32_t *, int32_t); 1607c478bd9Sstevel@tonic-gate extern uint_t atomic_add_int_nv(volatile uint_t *, int); 1617c478bd9Sstevel@tonic-gate extern void *atomic_add_ptr_nv(volatile void *, ssize_t); 1627c478bd9Sstevel@tonic-gate extern ulong_t atomic_add_long_nv(volatile ulong_t *, long); 1637c478bd9Sstevel@tonic-gate #if defined(_KERNEL) || defined(_INT64_TYPE) 1647c478bd9Sstevel@tonic-gate extern uint64_t atomic_add_64_nv(volatile uint64_t *, int64_t); 1657c478bd9Sstevel@tonic-gate #endif 1667c478bd9Sstevel@tonic-gate 1677c478bd9Sstevel@tonic-gate /* 1687c478bd9Sstevel@tonic-gate * logical OR bits with target and return new value. 1697c478bd9Sstevel@tonic-gate */ 1707c478bd9Sstevel@tonic-gate extern uint8_t atomic_or_8_nv(volatile uint8_t *, uint8_t); 1717c478bd9Sstevel@tonic-gate extern uchar_t atomic_or_uchar_nv(volatile uchar_t *, uchar_t); 1727c478bd9Sstevel@tonic-gate extern uint16_t atomic_or_16_nv(volatile uint16_t *, uint16_t); 1737c478bd9Sstevel@tonic-gate extern ushort_t atomic_or_ushort_nv(volatile ushort_t *, ushort_t); 1747c478bd9Sstevel@tonic-gate extern uint32_t atomic_or_32_nv(volatile uint32_t *, uint32_t); 1757c478bd9Sstevel@tonic-gate extern uint_t atomic_or_uint_nv(volatile uint_t *, uint_t); 1767c478bd9Sstevel@tonic-gate extern ulong_t atomic_or_ulong_nv(volatile ulong_t *, ulong_t); 1777c478bd9Sstevel@tonic-gate #if defined(_KERNEL) || defined(_INT64_TYPE) 1787c478bd9Sstevel@tonic-gate extern uint64_t atomic_or_64_nv(volatile uint64_t *, uint64_t); 1797c478bd9Sstevel@tonic-gate #endif 1807c478bd9Sstevel@tonic-gate 1817c478bd9Sstevel@tonic-gate /* 1827c478bd9Sstevel@tonic-gate * logical AND bits with target and return new value. 1837c478bd9Sstevel@tonic-gate */ 1847c478bd9Sstevel@tonic-gate extern uint8_t atomic_and_8_nv(volatile uint8_t *, uint8_t); 1857c478bd9Sstevel@tonic-gate extern uchar_t atomic_and_uchar_nv(volatile uchar_t *, uchar_t); 1867c478bd9Sstevel@tonic-gate extern uint16_t atomic_and_16_nv(volatile uint16_t *, uint16_t); 1877c478bd9Sstevel@tonic-gate extern ushort_t atomic_and_ushort_nv(volatile ushort_t *, ushort_t); 1887c478bd9Sstevel@tonic-gate extern uint32_t atomic_and_32_nv(volatile uint32_t *, uint32_t); 1897c478bd9Sstevel@tonic-gate extern uint_t atomic_and_uint_nv(volatile uint_t *, uint_t); 1907c478bd9Sstevel@tonic-gate extern ulong_t atomic_and_ulong_nv(volatile ulong_t *, ulong_t); 1917c478bd9Sstevel@tonic-gate #if defined(_KERNEL) || defined(_INT64_TYPE) 1927c478bd9Sstevel@tonic-gate extern uint64_t atomic_and_64_nv(volatile uint64_t *, uint64_t); 1937c478bd9Sstevel@tonic-gate #endif 1947c478bd9Sstevel@tonic-gate 1957c478bd9Sstevel@tonic-gate /* 1967c478bd9Sstevel@tonic-gate * If *arg1 == arg2, set *arg1 = arg3; return old value 1977c478bd9Sstevel@tonic-gate */ 1987c478bd9Sstevel@tonic-gate extern uint8_t atomic_cas_8(volatile uint8_t *, uint8_t, uint8_t); 1997c478bd9Sstevel@tonic-gate extern uchar_t atomic_cas_uchar(volatile uchar_t *, uchar_t, uchar_t); 2007c478bd9Sstevel@tonic-gate extern uint16_t atomic_cas_16(volatile uint16_t *, uint16_t, uint16_t); 2017c478bd9Sstevel@tonic-gate extern ushort_t atomic_cas_ushort(volatile ushort_t *, ushort_t, ushort_t); 2027c478bd9Sstevel@tonic-gate extern uint32_t atomic_cas_32(volatile uint32_t *, uint32_t, uint32_t); 2037c478bd9Sstevel@tonic-gate extern uint_t atomic_cas_uint(volatile uint_t *, uint_t, uint_t); 2047c478bd9Sstevel@tonic-gate extern void *atomic_cas_ptr(volatile void *, void *, void *); 2057c478bd9Sstevel@tonic-gate extern ulong_t atomic_cas_ulong(volatile ulong_t *, ulong_t, ulong_t); 2067c478bd9Sstevel@tonic-gate #if defined(_KERNEL) || defined(_INT64_TYPE) 2077c478bd9Sstevel@tonic-gate extern uint64_t atomic_cas_64(volatile uint64_t *, uint64_t, uint64_t); 2087c478bd9Sstevel@tonic-gate #endif 2097c478bd9Sstevel@tonic-gate 2107c478bd9Sstevel@tonic-gate /* 2117c478bd9Sstevel@tonic-gate * Swap target and return old value 2127c478bd9Sstevel@tonic-gate */ 2137c478bd9Sstevel@tonic-gate extern uint8_t atomic_swap_8(volatile uint8_t *, uint8_t); 2147c478bd9Sstevel@tonic-gate extern uchar_t atomic_swap_uchar(volatile uchar_t *, uchar_t); 2157c478bd9Sstevel@tonic-gate extern uint16_t atomic_swap_16(volatile uint16_t *, uint16_t); 2167c478bd9Sstevel@tonic-gate extern ushort_t atomic_swap_ushort(volatile ushort_t *, ushort_t); 2177c478bd9Sstevel@tonic-gate extern uint32_t atomic_swap_32(volatile uint32_t *, uint32_t); 2187c478bd9Sstevel@tonic-gate extern uint_t atomic_swap_uint(volatile uint_t *, uint_t); 2197c478bd9Sstevel@tonic-gate extern void *atomic_swap_ptr(volatile void *, void *); 2207c478bd9Sstevel@tonic-gate extern ulong_t atomic_swap_ulong(volatile ulong_t *, ulong_t); 2217c478bd9Sstevel@tonic-gate #if defined(_KERNEL) || defined(_INT64_TYPE) 2227c478bd9Sstevel@tonic-gate extern uint64_t atomic_swap_64(volatile uint64_t *, uint64_t); 2237c478bd9Sstevel@tonic-gate #endif 2247c478bd9Sstevel@tonic-gate 2257c478bd9Sstevel@tonic-gate /* 2267c478bd9Sstevel@tonic-gate * Perform an exclusive atomic bit set/clear on a target. 2277c478bd9Sstevel@tonic-gate * Returns 0 if bit was sucessfully set/cleared, or -1 2287c478bd9Sstevel@tonic-gate * if the bit was already set/cleared. 2297c478bd9Sstevel@tonic-gate */ 2307c478bd9Sstevel@tonic-gate extern int atomic_set_long_excl(volatile ulong_t *, uint_t); 2317c478bd9Sstevel@tonic-gate extern int atomic_clear_long_excl(volatile ulong_t *, uint_t); 2327c478bd9Sstevel@tonic-gate 2337c478bd9Sstevel@tonic-gate /* 2347c478bd9Sstevel@tonic-gate * Generic memory barrier used during lock entry, placed after the 2357c478bd9Sstevel@tonic-gate * memory operation that acquires the lock to guarantee that the lock 2367c478bd9Sstevel@tonic-gate * protects its data. No stores from after the memory barrier will 2377c478bd9Sstevel@tonic-gate * reach visibility, and no loads from after the barrier will be 2387c478bd9Sstevel@tonic-gate * resolved, before the lock acquisition reaches global visibility. 2397c478bd9Sstevel@tonic-gate */ 2407c478bd9Sstevel@tonic-gate extern void membar_enter(void); 2417c478bd9Sstevel@tonic-gate 2427c478bd9Sstevel@tonic-gate /* 2437c478bd9Sstevel@tonic-gate * Generic memory barrier used during lock exit, placed before the 2447c478bd9Sstevel@tonic-gate * memory operation that releases the lock to guarantee that the lock 2457c478bd9Sstevel@tonic-gate * protects its data. All loads and stores issued before the barrier 2467c478bd9Sstevel@tonic-gate * will be resolved before the subsequent lock update reaches visibility. 2477c478bd9Sstevel@tonic-gate */ 2487c478bd9Sstevel@tonic-gate extern void membar_exit(void); 2497c478bd9Sstevel@tonic-gate 2507c478bd9Sstevel@tonic-gate /* 2517c478bd9Sstevel@tonic-gate * Arrange that all stores issued before this point in the code reach 2527c478bd9Sstevel@tonic-gate * global visibility before any stores that follow; useful in producer 2537c478bd9Sstevel@tonic-gate * modules that update a data item, then set a flag that it is available. 2547c478bd9Sstevel@tonic-gate * The memory barrier guarantees that the available flag is not visible 2557c478bd9Sstevel@tonic-gate * earlier than the updated data, i.e. it imposes store ordering. 2567c478bd9Sstevel@tonic-gate */ 2577c478bd9Sstevel@tonic-gate extern void membar_producer(void); 2587c478bd9Sstevel@tonic-gate 2597c478bd9Sstevel@tonic-gate /* 2607c478bd9Sstevel@tonic-gate * Arrange that all loads issued before this point in the code are 2617c478bd9Sstevel@tonic-gate * completed before any subsequent loads; useful in consumer modules 2627c478bd9Sstevel@tonic-gate * that check to see if data is available and read the data. 2637c478bd9Sstevel@tonic-gate * The memory barrier guarantees that the data is not sampled until 2647c478bd9Sstevel@tonic-gate * after the available flag has been seen, i.e. it imposes load ordering. 2657c478bd9Sstevel@tonic-gate */ 2667c478bd9Sstevel@tonic-gate extern void membar_consumer(void); 2677c478bd9Sstevel@tonic-gate #endif 2687c478bd9Sstevel@tonic-gate 2697c478bd9Sstevel@tonic-gate #if !defined(_KERNEL) && !defined(__STDC__) 2707c478bd9Sstevel@tonic-gate extern void atomic_inc_8(); 2717c478bd9Sstevel@tonic-gate extern void atomic_inc_uchar(); 2727c478bd9Sstevel@tonic-gate extern void atomic_inc_16(); 2737c478bd9Sstevel@tonic-gate extern void atomic_inc_ushort(); 2747c478bd9Sstevel@tonic-gate extern void atomic_inc_32(); 2757c478bd9Sstevel@tonic-gate extern void atomic_inc_uint(); 2767c478bd9Sstevel@tonic-gate extern void atomic_inc_ulong(); 2777c478bd9Sstevel@tonic-gate #if defined(_INT64_TYPE) 2787c478bd9Sstevel@tonic-gate extern void atomic_inc_64(); 2797c478bd9Sstevel@tonic-gate #endif /* defined(_INT64_TYPE) */ 2807c478bd9Sstevel@tonic-gate extern void atomic_dec_8(); 2817c478bd9Sstevel@tonic-gate extern void atomic_dec_uchar(); 2827c478bd9Sstevel@tonic-gate extern void atomic_dec_16(); 2837c478bd9Sstevel@tonic-gate extern void atomic_dec_ushort(); 2847c478bd9Sstevel@tonic-gate extern void atomic_dec_32(); 2857c478bd9Sstevel@tonic-gate extern void atomic_dec_uint(); 2867c478bd9Sstevel@tonic-gate extern void atomic_dec_ulong(); 2877c478bd9Sstevel@tonic-gate #if defined(_INT64_TYPE) 2887c478bd9Sstevel@tonic-gate extern void atomic_dec_64(); 2897c478bd9Sstevel@tonic-gate #endif /* defined(_INT64_TYPE) */ 2907c478bd9Sstevel@tonic-gate extern void atomic_add_8(); 2917c478bd9Sstevel@tonic-gate extern void atomic_add_char(); 2927c478bd9Sstevel@tonic-gate extern void atomic_add_16(); 2937c478bd9Sstevel@tonic-gate extern void atomic_add_short(); 2947c478bd9Sstevel@tonic-gate extern void atomic_add_32(); 2957c478bd9Sstevel@tonic-gate extern void atomic_add_int(); 2967c478bd9Sstevel@tonic-gate extern void atomic_add_ptr(); 2977c478bd9Sstevel@tonic-gate extern void atomic_add_long(); 2987c478bd9Sstevel@tonic-gate #if defined(_INT64_TYPE) 2997c478bd9Sstevel@tonic-gate extern void atomic_add_64(); 3007c478bd9Sstevel@tonic-gate #endif /* defined(_INT64_TYPE) */ 3017c478bd9Sstevel@tonic-gate extern void atomic_or_8(); 3027c478bd9Sstevel@tonic-gate extern void atomic_or_uchar(); 3037c478bd9Sstevel@tonic-gate extern void atomic_or_16(); 3047c478bd9Sstevel@tonic-gate extern void atomic_or_ushort(); 3057c478bd9Sstevel@tonic-gate extern void atomic_or_32(); 3067c478bd9Sstevel@tonic-gate extern void atomic_or_uint(); 3077c478bd9Sstevel@tonic-gate extern void atomic_or_ulong(); 3087c478bd9Sstevel@tonic-gate #if defined(_INT64_TYPE) 3097c478bd9Sstevel@tonic-gate extern void atomic_or_64(); 3107c478bd9Sstevel@tonic-gate #endif /* defined(_INT64_TYPE) */ 3117c478bd9Sstevel@tonic-gate extern void atomic_and_8(); 3127c478bd9Sstevel@tonic-gate extern void atomic_and_uchar(); 3137c478bd9Sstevel@tonic-gate extern void atomic_and_16(); 3147c478bd9Sstevel@tonic-gate extern void atomic_and_ushort(); 3157c478bd9Sstevel@tonic-gate extern void atomic_and_32(); 3167c478bd9Sstevel@tonic-gate extern void atomic_and_uint(); 3177c478bd9Sstevel@tonic-gate extern void atomic_and_ulong(); 3187c478bd9Sstevel@tonic-gate #if defined(_INT64_TYPE) 3197c478bd9Sstevel@tonic-gate extern void atomic_and_64(); 3207c478bd9Sstevel@tonic-gate #endif /* defined(_INT64_TYPE) */ 3217c478bd9Sstevel@tonic-gate extern uint8_t atomic_inc_8_nv(); 3227c478bd9Sstevel@tonic-gate extern uchar_t atomic_inc_uchar_nv(); 3237c478bd9Sstevel@tonic-gate extern uint16_t atomic_inc_16_nv(); 3247c478bd9Sstevel@tonic-gate extern ushort_t atomic_inc_ushort_nv(); 3257c478bd9Sstevel@tonic-gate extern uint32_t atomic_inc_32_nv(); 3267c478bd9Sstevel@tonic-gate extern uint_t atomic_inc_uint_nv(); 3277c478bd9Sstevel@tonic-gate extern ulong_t atomic_inc_ulong_nv(); 3287c478bd9Sstevel@tonic-gate #if defined(_INT64_TYPE) 3297c478bd9Sstevel@tonic-gate extern uint64_t atomic_inc_64_nv(); 3307c478bd9Sstevel@tonic-gate #endif /* defined(_INT64_TYPE) */ 3317c478bd9Sstevel@tonic-gate extern uint8_t atomic_dec_8_nv(); 3327c478bd9Sstevel@tonic-gate extern uchar_t atomic_dec_uchar_nv(); 3337c478bd9Sstevel@tonic-gate extern uint16_t atomic_dec_16_nv(); 3347c478bd9Sstevel@tonic-gate extern ushort_t atomic_dec_ushort_nv(); 3357c478bd9Sstevel@tonic-gate extern uint32_t atomic_dec_32_nv(); 3367c478bd9Sstevel@tonic-gate extern uint_t atomic_dec_uint_nv(); 3377c478bd9Sstevel@tonic-gate extern ulong_t atomic_dec_ulong_nv(); 3387c478bd9Sstevel@tonic-gate #if defined(_INT64_TYPE) 3397c478bd9Sstevel@tonic-gate extern uint64_t atomic_dec_64_nv(); 3407c478bd9Sstevel@tonic-gate #endif /* defined(_INT64_TYPE) */ 3417c478bd9Sstevel@tonic-gate extern uint8_t atomic_add_8_nv(); 3427c478bd9Sstevel@tonic-gate extern uchar_t atomic_add_char_nv(); 3437c478bd9Sstevel@tonic-gate extern uint16_t atomic_add_16_nv(); 3447c478bd9Sstevel@tonic-gate extern ushort_t atomic_add_short_nv(); 3457c478bd9Sstevel@tonic-gate extern uint32_t atomic_add_32_nv(); 3467c478bd9Sstevel@tonic-gate extern uint_t atomic_add_int_nv(); 3477c478bd9Sstevel@tonic-gate extern void *atomic_add_ptr_nv(); 3487c478bd9Sstevel@tonic-gate extern ulong_t atomic_add_long_nv(); 3497c478bd9Sstevel@tonic-gate #if defined(_INT64_TYPE) 3507c478bd9Sstevel@tonic-gate extern uint64_t atomic_add_64_nv(); 3517c478bd9Sstevel@tonic-gate #endif /* defined(_INT64_TYPE) */ 3527c478bd9Sstevel@tonic-gate extern uint8_t atomic_or_8_nv(); 3537c478bd9Sstevel@tonic-gate extern uchar_t atomic_or_uchar_nv(); 3547c478bd9Sstevel@tonic-gate extern uint16_t atomic_or_16_nv(); 3557c478bd9Sstevel@tonic-gate extern ushort_t atomic_or_ushort_nv(); 3567c478bd9Sstevel@tonic-gate extern uint32_t atomic_or_32_nv(); 3577c478bd9Sstevel@tonic-gate extern uint_t atomic_or_uint_nv(); 3587c478bd9Sstevel@tonic-gate extern ulong_t atomic_or_ulong_nv(); 3597c478bd9Sstevel@tonic-gate #if defined(_INT64_TYPE) 3607c478bd9Sstevel@tonic-gate extern uint64_t atomic_or_64_nv(); 3617c478bd9Sstevel@tonic-gate #endif /* defined(_INT64_TYPE) */ 3627c478bd9Sstevel@tonic-gate extern uint8_t atomic_and_8_nv(); 3637c478bd9Sstevel@tonic-gate extern uchar_t atomic_and_uchar_nv(); 3647c478bd9Sstevel@tonic-gate extern uint16_t atomic_and_16_nv(); 3657c478bd9Sstevel@tonic-gate extern ushort_t atomic_and_ushort_nv(); 3667c478bd9Sstevel@tonic-gate extern uint32_t atomic_and_32_nv(); 3677c478bd9Sstevel@tonic-gate extern uint_t atomic_and_uint_nv(); 3687c478bd9Sstevel@tonic-gate extern ulong_t atomic_and_ulong_nv(); 3697c478bd9Sstevel@tonic-gate #if defined(_INT64_TYPE) 3707c478bd9Sstevel@tonic-gate extern uint64_t atomic_and_64_nv(); 3717c478bd9Sstevel@tonic-gate #endif /* defined(_INT64_TYPE) */ 3727c478bd9Sstevel@tonic-gate extern uint8_t atomic_cas_8(); 3737c478bd9Sstevel@tonic-gate extern uchar_t atomic_cas_uchar(); 3747c478bd9Sstevel@tonic-gate extern uint16_t atomic_cas_16(); 3757c478bd9Sstevel@tonic-gate extern ushort_t atomic_cas_ushort(); 3767c478bd9Sstevel@tonic-gate extern uint32_t atomic_cas_32(); 3777c478bd9Sstevel@tonic-gate extern uint_t atomic_cas_uint(); 3787c478bd9Sstevel@tonic-gate extern void *atomic_cas_ptr(); 3797c478bd9Sstevel@tonic-gate extern ulong_t atomic_cas_ulong(); 3807c478bd9Sstevel@tonic-gate #if defined(_INT64_TYPE) 3817c478bd9Sstevel@tonic-gate extern uint64_t atomic_cas_64(); 3827c478bd9Sstevel@tonic-gate #endif /* defined(_INT64_TYPE) */ 3837c478bd9Sstevel@tonic-gate extern uint8_t atomic_swap_8(); 3847c478bd9Sstevel@tonic-gate extern uchar_t atomic_swap_uchar(); 3857c478bd9Sstevel@tonic-gate extern uint16_t atomic_swap_16(); 3867c478bd9Sstevel@tonic-gate extern ushort_t atomic_swap_ushort(); 3877c478bd9Sstevel@tonic-gate extern uint32_t atomic_swap_32(); 3887c478bd9Sstevel@tonic-gate extern uint_t atomic_swap_uint(); 3897c478bd9Sstevel@tonic-gate extern void *atomic_swap_ptr(); 3907c478bd9Sstevel@tonic-gate extern ulong_t atomic_swap_ulong(); 3917c478bd9Sstevel@tonic-gate #if defined(_INT64_TYPE) 3927c478bd9Sstevel@tonic-gate extern uint64_t atomic_swap_64(); 3937c478bd9Sstevel@tonic-gate #endif /* defined(_INT64_TYPE) */ 3947c478bd9Sstevel@tonic-gate 3957c478bd9Sstevel@tonic-gate 3967c478bd9Sstevel@tonic-gate extern int atomic_set_long_excl(); 3977c478bd9Sstevel@tonic-gate extern int atomic_clear_long_excl(); 3987c478bd9Sstevel@tonic-gate 3997c478bd9Sstevel@tonic-gate extern void membar_enter(); 4007c478bd9Sstevel@tonic-gate extern void membar_exit(); 4017c478bd9Sstevel@tonic-gate extern void membar_producer(); 4027c478bd9Sstevel@tonic-gate extern void membar_consumer(); 4037c478bd9Sstevel@tonic-gate 4047c478bd9Sstevel@tonic-gate #endif 4057c478bd9Sstevel@tonic-gate 4067c478bd9Sstevel@tonic-gate #if defined(_KERNEL) 4077c478bd9Sstevel@tonic-gate 4087c478bd9Sstevel@tonic-gate #if defined(_LP64) || defined(_ILP32) 4097c478bd9Sstevel@tonic-gate #define atomic_add_ip atomic_add_long 4107c478bd9Sstevel@tonic-gate #define atomic_add_ip_nv atomic_add_long_nv 4117c478bd9Sstevel@tonic-gate #define casip atomic_cas_ulong 4127c478bd9Sstevel@tonic-gate #endif 4137c478bd9Sstevel@tonic-gate 4147c478bd9Sstevel@tonic-gate #if defined(__sparc) 4157c478bd9Sstevel@tonic-gate extern uint8_t ldstub(uint8_t *); 4167c478bd9Sstevel@tonic-gate #endif 4177c478bd9Sstevel@tonic-gate 4187c478bd9Sstevel@tonic-gate /* 4197c478bd9Sstevel@tonic-gate * Legacy kernel interfaces; they will go away (eventually). 4207c478bd9Sstevel@tonic-gate */ 4217c478bd9Sstevel@tonic-gate extern uint8_t cas8(uint8_t *, uint8_t, uint8_t); 4227c478bd9Sstevel@tonic-gate extern uint32_t cas32(uint32_t *, uint32_t, uint32_t); 4237c478bd9Sstevel@tonic-gate extern uint64_t cas64(uint64_t *, uint64_t, uint64_t); 4247c478bd9Sstevel@tonic-gate extern ulong_t caslong(ulong_t *, ulong_t, ulong_t); 4257c478bd9Sstevel@tonic-gate extern void *casptr(void *, void *, void *); 4267c478bd9Sstevel@tonic-gate extern void atomic_and_long(ulong_t *, ulong_t); 4277c478bd9Sstevel@tonic-gate extern void atomic_or_long(ulong_t *, ulong_t); 4287c478bd9Sstevel@tonic-gate #if defined(__sparc) 4297c478bd9Sstevel@tonic-gate extern uint32_t swapl(uint32_t *, uint32_t); 4307c478bd9Sstevel@tonic-gate #endif 4317c478bd9Sstevel@tonic-gate 4327c478bd9Sstevel@tonic-gate #endif /* _KERNEL */ 4337c478bd9Sstevel@tonic-gate 4347c478bd9Sstevel@tonic-gate #ifdef __cplusplus 4357c478bd9Sstevel@tonic-gate } 4367c478bd9Sstevel@tonic-gate #endif 4377c478bd9Sstevel@tonic-gate 4387c478bd9Sstevel@tonic-gate #endif /* _SYS_ATOMIC_H */ 439