Deleted Added
full compact
atomic.h (150182) atomic.h (150627)
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/amd64/include/atomic.h 150182 2005-09-15 19:31:22Z jhb $
26 * $FreeBSD: head/sys/amd64/include/atomic.h 150627 2005-09-27 17:39:11Z jhb $
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

--- 33 unchanged lines hidden (view full) ---

68 * This allows kernel modules to be portable between UP and SMP systems.
69 */
70#if defined(KLD_MODULE) || !(defined(__GNUCLIKE_ASM) && defined(__CC_SUPPORTS___INLINE))
71#define ATOMIC_ASM(NAME, TYPE, OP, CONS, V) \
72void atomic_##NAME##_##TYPE(volatile u_##TYPE *p, u_##TYPE v)
73
74int atomic_cmpset_int(volatile u_int *dst, u_int exp, u_int src);
75int atomic_cmpset_long(volatile u_long *dst, u_long exp, u_long src);
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

--- 33 unchanged lines hidden (view full) ---

68 * This allows kernel modules to be portable between UP and SMP systems.
69 */
70#if defined(KLD_MODULE) || !(defined(__GNUCLIKE_ASM) && defined(__CC_SUPPORTS___INLINE))
71#define ATOMIC_ASM(NAME, TYPE, OP, CONS, V) \
72void atomic_##NAME##_##TYPE(volatile u_##TYPE *p, u_##TYPE v)
73
74int atomic_cmpset_int(volatile u_int *dst, u_int exp, u_int src);
75int atomic_cmpset_long(volatile u_long *dst, u_long exp, u_long src);
76u_int atomic_fetchadd_int(volatile u_int *p, u_int v);
76
77#define ATOMIC_STORE_LOAD(TYPE, LOP, SOP) \
78u_##TYPE atomic_load_acq_##TYPE(volatile u_##TYPE *p); \
79void atomic_store_rel_##TYPE(volatile u_##TYPE *p, u_##TYPE v)
80
81#else /* !KLD_MODULE && __GNUCLIKE_ASM && __CC_SUPPORTS___INLINE */
82
83/*

--- 65 unchanged lines hidden (view full) ---

149 "=m" (*dst) /* 1 */
150 : "r" (src), /* 2 */
151 "m" (*dst) /* 3 */
152 : "memory");
153
154 return (res);
155}
156
77
78#define ATOMIC_STORE_LOAD(TYPE, LOP, SOP) \
79u_##TYPE atomic_load_acq_##TYPE(volatile u_##TYPE *p); \
80void atomic_store_rel_##TYPE(volatile u_##TYPE *p, u_##TYPE v)
81
82#else /* !KLD_MODULE && __GNUCLIKE_ASM && __CC_SUPPORTS___INLINE */
83
84/*

--- 65 unchanged lines hidden (view full) ---

150 "=m" (*dst) /* 1 */
151 : "r" (src), /* 2 */
152 "m" (*dst) /* 3 */
153 : "memory");
154
155 return (res);
156}
157
158/*
159 * Atomically add the value of v to the integer pointed to by p and return
160 * the previous value of *p.
161 */
162static __inline u_int
163atomic_fetchadd_int(volatile u_int *p, u_int v)
164{
165
166 __asm __volatile (
167 " " __XSTRING(MPLOCKED) " "
168 " xaddl %0, %1 ; "
169 "# atomic_fetchadd_int"
170 : "+r" (v), /* 0 (result) */
171 "=m" (*p) /* 1 */
172 : "m" (*p)); /* 2 */
173
174 return (v);
175}
176
157#if defined(_KERNEL) && !defined(SMP)
158
159/*
160 * We assume that a = b will do atomic loads and stores. However, on a
161 * PentiumPro or higher, reads may pass writes, so for that case we have
162 * to use a serializing instruction (i.e. with LOCK) to do the load in
163 * SMP kernels. For UP kernels, however, the cache of the single processor
164 * is always consistent, so we don't need any memory barriers.

--- 205 unchanged lines hidden (view full) ---

370#define atomic_subtract_acq_32 atomic_subtract_acq_int
371#define atomic_subtract_rel_32 atomic_subtract_rel_int
372#define atomic_load_acq_32 atomic_load_acq_int
373#define atomic_store_rel_32 atomic_store_rel_int
374#define atomic_cmpset_32 atomic_cmpset_int
375#define atomic_cmpset_acq_32 atomic_cmpset_acq_int
376#define atomic_cmpset_rel_32 atomic_cmpset_rel_int
377#define atomic_readandclear_32 atomic_readandclear_int
177#if defined(_KERNEL) && !defined(SMP)
178
179/*
180 * We assume that a = b will do atomic loads and stores. However, on a
181 * PentiumPro or higher, reads may pass writes, so for that case we have
182 * to use a serializing instruction (i.e. with LOCK) to do the load in
183 * SMP kernels. For UP kernels, however, the cache of the single processor
184 * is always consistent, so we don't need any memory barriers.

--- 205 unchanged lines hidden (view full) ---

390#define atomic_subtract_acq_32 atomic_subtract_acq_int
391#define atomic_subtract_rel_32 atomic_subtract_rel_int
392#define atomic_load_acq_32 atomic_load_acq_int
393#define atomic_store_rel_32 atomic_store_rel_int
394#define atomic_cmpset_32 atomic_cmpset_int
395#define atomic_cmpset_acq_32 atomic_cmpset_acq_int
396#define atomic_cmpset_rel_32 atomic_cmpset_rel_int
397#define atomic_readandclear_32 atomic_readandclear_int
398#define atomic_fetchadd_32 atomic_fetchadd_int
378
379/* Operations on 64-bit quad words. */
380#define atomic_set_64 atomic_set_long
381#define atomic_set_acq_64 atomic_set_acq_long
382#define atomic_set_rel_64 atomic_set_rel_long
383#define atomic_clear_64 atomic_clear_long
384#define atomic_clear_acq_64 atomic_clear_acq_long
385#define atomic_clear_rel_64 atomic_clear_rel_long

--- 35 unchanged lines hidden ---
399
400/* Operations on 64-bit quad words. */
401#define atomic_set_64 atomic_set_long
402#define atomic_set_acq_64 atomic_set_acq_long
403#define atomic_set_rel_64 atomic_set_rel_long
404#define atomic_clear_64 atomic_clear_long
405#define atomic_clear_acq_64 atomic_clear_acq_long
406#define atomic_clear_rel_64 atomic_clear_rel_long

--- 35 unchanged lines hidden ---