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/i386/include/atomic.h 150182 2005-09-15 19:31:22Z jhb $
26 * $FreeBSD: head/sys/i386/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

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

67 * Kernel modules call real functions which are built into the kernel.
68 * This allows kernel modules to be portable between UP and SMP systems.
69 */
70#if defined(KLD_MODULE) || !defined(__GNUCLIKE_ASM)
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);
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

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

67 * Kernel modules call real functions which are built into the kernel.
68 * This allows kernel modules to be portable between UP and SMP systems.
69 */
70#if defined(KLD_MODULE) || !defined(__GNUCLIKE_ASM)
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);
75u_int atomic_fetchadd_int(volatile u_int *p, u_int v);
75
76#define ATOMIC_STORE_LOAD(TYPE, LOP, SOP) \
77u_##TYPE atomic_load_acq_##TYPE(volatile u_##TYPE *p); \
78void atomic_store_rel_##TYPE(volatile u_##TYPE *p, u_##TYPE v)
79
80#else /* !KLD_MODULE && __GNUCLIKE_ASM */
81
82/*

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

158 "m" (*dst) /* 3 */
159 : "memory");
160
161 return (res);
162}
163
164#endif /* defined(CPU_DISABLE_CMPXCHG) */
165
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 */
82
83/*

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

159 "m" (*dst) /* 3 */
160 : "memory");
161
162 return (res);
163}
164
165#endif /* defined(CPU_DISABLE_CMPXCHG) */
166
167/*
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) " "
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}
185
166#if defined(_KERNEL) && !defined(SMP)
167
168/*
169 * We assume that a = b will do atomic loads and stores. However, on a
170 * PentiumPro or higher, reads may pass writes, so for that case we have
171 * to use a serializing instruction (i.e. with LOCK) to do the load in
172 * SMP kernels. For UP kernels, however, the cache of the single processor
173 * is always consistent, so we don't need any memory barriers.

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

387#define atomic_subtract_acq_32 atomic_subtract_acq_int
388#define atomic_subtract_rel_32 atomic_subtract_rel_int
389#define atomic_load_acq_32 atomic_load_acq_int
390#define atomic_store_rel_32 atomic_store_rel_int
391#define atomic_cmpset_32 atomic_cmpset_int
392#define atomic_cmpset_acq_32 atomic_cmpset_acq_int
393#define atomic_cmpset_rel_32 atomic_cmpset_rel_int
394#define atomic_readandclear_32 atomic_readandclear_int
186#if defined(_KERNEL) && !defined(SMP)
187
188/*
189 * We assume that a = b will do atomic loads and stores. However, on a
190 * PentiumPro or higher, reads may pass writes, so for that case we have
191 * to use a serializing instruction (i.e. with LOCK) to do the load in
192 * SMP kernels. For UP kernels, however, the cache of the single processor
193 * is always consistent, so we don't need any memory barriers.

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

407#define atomic_subtract_acq_32 atomic_subtract_acq_int
408#define atomic_subtract_rel_32 atomic_subtract_rel_int
409#define atomic_load_acq_32 atomic_load_acq_int
410#define atomic_store_rel_32 atomic_store_rel_int
411#define atomic_cmpset_32 atomic_cmpset_int
412#define atomic_cmpset_acq_32 atomic_cmpset_acq_int
413#define atomic_cmpset_rel_32 atomic_cmpset_rel_int
414#define atomic_readandclear_32 atomic_readandclear_int
415#define atomic_fetchadd_32 atomic_fetchadd_int
395
396/* Operations on pointers. */
397#define atomic_set_ptr atomic_set_int
398#define atomic_set_acq_ptr atomic_set_acq_int
399#define atomic_set_rel_ptr atomic_set_rel_int
400#define atomic_clear_ptr atomic_clear_int
401#define atomic_clear_acq_ptr atomic_clear_acq_int
402#define atomic_clear_rel_ptr atomic_clear_rel_int

--- 15 unchanged lines hidden ---
416
417/* Operations on pointers. */
418#define atomic_set_ptr atomic_set_int
419#define atomic_set_acq_ptr atomic_set_acq_int
420#define atomic_set_rel_ptr atomic_set_rel_int
421#define atomic_clear_ptr atomic_clear_int
422#define atomic_clear_acq_ptr atomic_clear_acq_int
423#define atomic_clear_rel_ptr atomic_clear_rel_int

--- 15 unchanged lines hidden ---