2 * bitops.c: atomic operations which got too long to be inlined all over
5 * Copyright 1999 Philipp Rumpf (prumpf@tux.org)
6 * Copyright 2000 Grant Grundler (grundler@cup.hp.com)
9 #include <linux/config.h>
10 #include <linux/kernel.h>
11 #include <linux/spinlock.h>
12 #include <asm/system.h>
13 #include <asm/atomic.h>
16 spinlock_t __atomic_hash
[ATOMIC_HASH_SIZE
] __lock_aligned
= {
17 [0 ... (ATOMIC_HASH_SIZE
-1)] = SPIN_LOCK_UNLOCKED
22 unsigned long __xchg64(unsigned long x
, unsigned long *ptr
)
24 unsigned long temp
, flags
;
26 _atomic_spin_lock_irqsave(ptr
, flags
);
29 _atomic_spin_unlock_irqrestore(ptr
, flags
);
34 unsigned long __xchg32(int x
, int *ptr
)
39 _atomic_spin_lock_irqsave(ptr
, flags
);
40 temp
= (long) *ptr
; /* XXX - sign extension wanted? */
42 _atomic_spin_unlock_irqrestore(ptr
, flags
);
43 return (unsigned long)temp
;
47 unsigned long __xchg8(char x
, char *ptr
)
52 _atomic_spin_lock_irqsave(ptr
, flags
);
53 temp
= (long) *ptr
; /* XXX - sign extension wanted? */
55 _atomic_spin_unlock_irqrestore(ptr
, flags
);
56 return (unsigned long)temp
;
61 unsigned long __cmpxchg_u64(volatile unsigned long *ptr
, unsigned long old
, unsigned long new)
66 _atomic_spin_lock_irqsave(ptr
, flags
);
67 if ((prev
= *ptr
) == old
)
69 _atomic_spin_unlock_irqrestore(ptr
, flags
);
74 unsigned long __cmpxchg_u32(volatile unsigned int *ptr
, unsigned int old
, unsigned int new)
79 _atomic_spin_lock_irqsave(ptr
, flags
);
80 if ((prev
= *ptr
) == old
)
82 _atomic_spin_unlock_irqrestore(ptr
, flags
);
83 return (unsigned long)prev
;