Deleted Added
full compact
atomic.h (49043) atomic.h (49999)
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 * $Id: atomic.h,v 1.3 1999/07/13 06:35:25 alc Exp $
26 * $Id: atomic.h,v 1.4 1999/07/23 23:45:19 alc Exp $
27 */
28#ifndef _MACHINE_ATOMIC_H_
29#define _MACHINE_ATOMIC_H_
30
31/*
32 * Various simple arithmetic on memory which is atomic in the presence
33 * of interrupts and multiple processors.
34 *

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

49 *
50 * atomic_set_long(P, V) (*(u_long*)(P) |= (V))
51 * atomic_clear_long(P, V) (*(u_long*)(P) &= ~(V))
52 * atomic_add_long(P, V) (*(u_long*)(P) += (V))
53 * atomic_subtract_long(P, V) (*(u_long*)(P) -= (V))
54 */
55
56/*
27 */
28#ifndef _MACHINE_ATOMIC_H_
29#define _MACHINE_ATOMIC_H_
30
31/*
32 * Various simple arithmetic on memory which is atomic in the presence
33 * of interrupts and multiple processors.
34 *

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

49 *
50 * atomic_set_long(P, V) (*(u_long*)(P) |= (V))
51 * atomic_clear_long(P, V) (*(u_long*)(P) &= ~(V))
52 * atomic_add_long(P, V) (*(u_long*)(P) += (V))
53 * atomic_subtract_long(P, V) (*(u_long*)(P) -= (V))
54 */
55
56/*
57 * Make kernel modules portable between UP and SMP.
57 * The above functions are expanded inline in the statically-linked
58 * kernel. Lock prefixes are generated if an SMP kernel is being
59 * built.
60 *
61 * Kernel modules call real functions which are built into the kernel.
62 * This allows kernel modules to be portable between UP and SMP systems.
58 */
63 */
59#if defined(SMP) || defined(KLD_MODULE)
64#if defined(KLD_MODULE)
65#define ATOMIC_ASM(NAME, TYPE, OP, V) \
66 extern void atomic_##NAME##_##TYPE(volatile u_##TYPE *p, u_##TYPE v);
67
68#else /* !KLD_MODULE */
69#if defined(SMP)
60#define MPLOCKED "lock ; "
61#else
62#define MPLOCKED
63#endif
64
65/*
66 * The assembly is volatilized to demark potential before-and-after side
67 * effects if an interrupt or SMP collision were to occur.
68 */
69#define ATOMIC_ASM(NAME, TYPE, OP, V) \
70static __inline void \
71atomic_##NAME##_##TYPE(volatile u_##TYPE *p, u_##TYPE v)\
72{ \
73 __asm __volatile(MPLOCKED OP \
74 : "=m" (*p) \
75 : "0" (*p), "ir" (V)); \
76}
70#define MPLOCKED "lock ; "
71#else
72#define MPLOCKED
73#endif
74
75/*
76 * The assembly is volatilized to demark potential before-and-after side
77 * effects if an interrupt or SMP collision were to occur.
78 */
79#define ATOMIC_ASM(NAME, TYPE, OP, V) \
80static __inline void \
81atomic_##NAME##_##TYPE(volatile u_##TYPE *p, u_##TYPE v)\
82{ \
83 __asm __volatile(MPLOCKED OP \
84 : "=m" (*p) \
85 : "0" (*p), "ir" (V)); \
86}
87#endif /* KLD_MODULE */
77
78ATOMIC_ASM(set, char, "orb %2,%0", v)
79ATOMIC_ASM(clear, char, "andb %2,%0", ~v)
80ATOMIC_ASM(add, char, "addb %2,%0", v)
81ATOMIC_ASM(subtract, char, "subb %2,%0", v)
82
83ATOMIC_ASM(set, short, "orw %2,%0", v)
84ATOMIC_ASM(clear, short, "andw %2,%0", ~v)

--- 14 unchanged lines hidden ---
88
89ATOMIC_ASM(set, char, "orb %2,%0", v)
90ATOMIC_ASM(clear, char, "andb %2,%0", ~v)
91ATOMIC_ASM(add, char, "addb %2,%0", v)
92ATOMIC_ASM(subtract, char, "subb %2,%0", v)
93
94ATOMIC_ASM(set, short, "orw %2,%0", v)
95ATOMIC_ASM(clear, short, "andw %2,%0", ~v)

--- 14 unchanged lines hidden ---