2 * linux/include/asm-arm26/atomic.h
4 * Copyright (c) 1996 Russell King.
5 * Modified for arm26 by Ian Molton
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
12 * 25-11-2004 IM Updated for 2.6.9
13 * 27-06-1996 RMK Created
14 * 13-04-1997 RMK Made functions atomic!
15 * 07-12-1997 RMK Upgraded for v2.1.
16 * 26-08-1998 PJB Added #ifdef __KERNEL__
18 * FIXME - its probably worth seeing what these compile into...
20 #ifndef __ASM_ARM_ATOMIC_H
21 #define __ASM_ARM_ATOMIC_H
23 #include <linux/config.h>
26 #error SMP is NOT supported
29 typedef struct { volatile int counter; } atomic_t;
31 #define ATOMIC_INIT(i) { (i) }
34 #include <asm/system.h>
36 #define atomic_read(v) ((v)->counter)
37 #define atomic_set(v,i) (((v)->counter) = (i))
39 static inline int atomic_add_return(int i, atomic_t *v)
44 local_irq_save(flags);
46 v->counter = val += i;
47 local_irq_restore(flags);
52 static inline int atomic_sub_return(int i, atomic_t *v)
57 local_irq_save(flags);
59 v->counter = val -= i;
60 local_irq_restore(flags);
65 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
70 local_irq_save(flags);
72 if (likely(ret == old))
74 local_irq_restore(flags);
79 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
81 static inline int atomic_add_unless(atomic_t *v, int a, int u)
86 local_irq_save(flags);
90 local_irq_restore(flags);
94 #define atomic_inc_not_zero(v) atomic_add_unless((v), 1, 0)
96 static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
100 local_irq_save(flags);
102 local_irq_restore(flags);
105 #define atomic_add(i, v) (void) atomic_add_return(i, v)
106 #define atomic_inc(v) (void) atomic_add_return(1, v)
107 #define atomic_sub(i, v) (void) atomic_sub_return(i, v)
108 #define atomic_dec(v) (void) atomic_sub_return(1, v)
110 #define atomic_inc_and_test(v) (atomic_add_return(1, v) == 0)
111 #define atomic_dec_and_test(v) (atomic_sub_return(1, v) == 0)
112 #define atomic_inc_return(v) (atomic_add_return(1, v))
113 #define atomic_dec_return(v) (atomic_sub_return(1, v))
115 #define atomic_add_negative(i,v) (atomic_add_return(i, v) < 0)
117 /* Atomic operations are already serializing on ARM26 */
118 #define smp_mb__before_atomic_dec() barrier()
119 #define smp_mb__after_atomic_dec() barrier()
120 #define smp_mb__before_atomic_inc() barrier()
121 #define smp_mb__after_atomic_inc() barrier()
123 #include <asm-generic/atomic.h>