atomic.h (165572) | atomic.h (165630) |
---|---|
1/*- 2 * Copyright (c) 1998 Doug Rabson 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 9 unchanged lines hidden (view full) --- 18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 * | 1/*- 2 * Copyright (c) 1998 Doug Rabson 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 9 unchanged lines hidden (view full) --- 18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 * |
26 * $FreeBSD: head/sys/i386/include/atomic.h 165572 2006-12-27 20:26:00Z bde $ | 26 * $FreeBSD: head/sys/i386/include/atomic.h 165630 2006-12-29 13:36:26Z bde $ |
27 */ 28#ifndef _MACHINE_ATOMIC_H_ 29#define _MACHINE_ATOMIC_H_ 30 31#ifndef _SYS_CDEFS_H_ 32#error this file needs sys/cdefs.h as a prerequisite 33#endif 34 --- 45 unchanged lines hidden (view full) --- 80 81#else /* !KLD_MODULE && __GNUCLIKE_ASM */ 82 83/* 84 * For userland, assume the SMP case and use lock prefixes so that 85 * the binaries will run on both types of systems. 86 */ 87#if defined(SMP) || !defined(_KERNEL) | 27 */ 28#ifndef _MACHINE_ATOMIC_H_ 29#define _MACHINE_ATOMIC_H_ 30 31#ifndef _SYS_CDEFS_H_ 32#error this file needs sys/cdefs.h as a prerequisite 33#endif 34 --- 45 unchanged lines hidden (view full) --- 80 81#else /* !KLD_MODULE && __GNUCLIKE_ASM */ 82 83/* 84 * For userland, assume the SMP case and use lock prefixes so that 85 * the binaries will run on both types of systems. 86 */ 87#if defined(SMP) || !defined(_KERNEL) |
88#define MPLOCKED lock ; | 88#define MPLOCKED "lock ; " |
89#else 90#define MPLOCKED 91#endif 92 93/* 94 * The assembly is volatilized to demark potential before-and-after side 95 * effects if an interrupt or SMP collision were to occur. 96 */ 97#define ATOMIC_ASM(NAME, TYPE, OP, CONS, V) \ 98static __inline void \ 99atomic_##NAME##_##TYPE(volatile u_##TYPE *p, u_##TYPE v)\ 100{ \ | 89#else 90#define MPLOCKED 91#endif 92 93/* 94 * The assembly is volatilized to demark potential before-and-after side 95 * effects if an interrupt or SMP collision were to occur. 96 */ 97#define ATOMIC_ASM(NAME, TYPE, OP, CONS, V) \ 98static __inline void \ 99atomic_##NAME##_##TYPE(volatile u_##TYPE *p, u_##TYPE v)\ 100{ \ |
101 __asm __volatile(__XSTRING(MPLOCKED) OP \ | 101 __asm __volatile(MPLOCKED OP \ |
102 : "=m" (*p) \ 103 : CONS (V), "m" (*p)); \ 104} \ 105struct __hack 106 107/* 108 * Atomic compare and set, used by the mutex functions 109 * --- 32 unchanged lines hidden (view full) --- 142#else /* defined(CPU_DISABLE_CMPXCHG) */ 143 144static __inline int 145atomic_cmpset_int(volatile u_int *dst, u_int exp, u_int src) 146{ 147 u_char res; 148 149 __asm __volatile ( | 102 : "=m" (*p) \ 103 : CONS (V), "m" (*p)); \ 104} \ 105struct __hack 106 107/* 108 * Atomic compare and set, used by the mutex functions 109 * --- 32 unchanged lines hidden (view full) --- 142#else /* defined(CPU_DISABLE_CMPXCHG) */ 143 144static __inline int 145atomic_cmpset_int(volatile u_int *dst, u_int exp, u_int src) 146{ 147 u_char res; 148 149 __asm __volatile ( |
150 " " __XSTRING(MPLOCKED) " " | 150 " " MPLOCKED " " |
151 " cmpxchgl %2,%1 ; " 152 " sete %0 ; " 153 "1: " 154 "# atomic_cmpset_int" 155 : "=a" (res), /* 0 */ 156 "=m" (*dst) /* 1 */ 157 : "r" (src), /* 2 */ 158 "a" (exp), /* 3 */ --- 9 unchanged lines hidden (view full) --- 168 * Atomically add the value of v to the integer pointed to by p and return 169 * the previous value of *p. 170 */ 171static __inline u_int 172atomic_fetchadd_int(volatile u_int *p, u_int v) 173{ 174 175 __asm __volatile ( | 151 " cmpxchgl %2,%1 ; " 152 " sete %0 ; " 153 "1: " 154 "# atomic_cmpset_int" 155 : "=a" (res), /* 0 */ 156 "=m" (*dst) /* 1 */ 157 : "r" (src), /* 2 */ 158 "a" (exp), /* 3 */ --- 9 unchanged lines hidden (view full) --- 168 * Atomically add the value of v to the integer pointed to by p and return 169 * the previous value of *p. 170 */ 171static __inline u_int 172atomic_fetchadd_int(volatile u_int *p, u_int v) 173{ 174 175 __asm __volatile ( |
176 " " __XSTRING(MPLOCKED) " " | 176 " " MPLOCKED " " |
177 " xaddl %0, %1 ; " 178 "# atomic_fetchadd_int" 179 : "+r" (v), /* 0 (result) */ 180 "=m" (*p) /* 1 */ 181 : "m" (*p)); /* 2 */ 182 183 return (v); 184} --- 24 unchanged lines hidden (view full) --- 209#else /* defined(SMP) */ 210 211#define ATOMIC_STORE_LOAD(TYPE, LOP, SOP) \ 212static __inline u_##TYPE \ 213atomic_load_acq_##TYPE(volatile u_##TYPE *p) \ 214{ \ 215 u_##TYPE res; \ 216 \ | 177 " xaddl %0, %1 ; " 178 "# atomic_fetchadd_int" 179 : "+r" (v), /* 0 (result) */ 180 "=m" (*p) /* 1 */ 181 : "m" (*p)); /* 2 */ 182 183 return (v); 184} --- 24 unchanged lines hidden (view full) --- 209#else /* defined(SMP) */ 210 211#define ATOMIC_STORE_LOAD(TYPE, LOP, SOP) \ 212static __inline u_##TYPE \ 213atomic_load_acq_##TYPE(volatile u_##TYPE *p) \ 214{ \ 215 u_##TYPE res; \ 216 \ |
217 __asm __volatile(__XSTRING(MPLOCKED) LOP \ | 217 __asm __volatile(MPLOCKED LOP \ |
218 : "=a" (res), /* 0 (result) */\ 219 "=m" (*p) /* 1 */ \ 220 : "m" (*p) /* 2 */ \ 221 : "memory"); \ 222 \ 223 return (res); \ 224} \ 225 \ --- 231 unchanged lines hidden --- | 218 : "=a" (res), /* 0 (result) */\ 219 "=m" (*p) /* 1 */ \ 220 : "m" (*p) /* 2 */ \ 221 : "memory"); \ 222 \ 223 return (res); \ 224} \ 225 \ --- 231 unchanged lines hidden --- |