1 #ifndef __ARCH_BLACKFIN_ATOMIC__
2 #define __ARCH_BLACKFIN_ATOMIC__
4 #include <linux/types.h>
5 #include <asm/system.h> /* local_irq_XXX() */
8 * Atomic operations that C can't guarantee us. Useful for
9 * resource counting etc..
11 * Generally we do not concern about SMP BFIN systems, so we don't have
14 * Tony Kou (tonyko@lineo.ca) Lineo Inc. 2001
17 #define ATOMIC_INIT(i) { (i) }
19 #define atomic_read(v) ((v)->counter)
20 #define atomic_set(v, i) (((v)->counter) = i)
22 static __inline__ void atomic_add(int i, atomic_t * v)
26 local_irq_save(flags);
28 local_irq_restore(flags);
31 static __inline__ void atomic_sub(int i, atomic_t * v)
35 local_irq_save(flags);
37 local_irq_restore(flags);
41 static inline int atomic_add_return(int i, atomic_t * v)
46 local_irq_save(flags);
49 local_irq_restore(flags);
55 #define atomic_add_negative(a, v) (atomic_add_return((a), (v)) < 0)
56 static inline int atomic_sub_return(int i, atomic_t * v)
61 local_irq_save(flags);
64 local_irq_restore(flags);
69 static __inline__ void atomic_inc(volatile atomic_t * v)
73 local_irq_save(flags);
75 local_irq_restore(flags);
78 #define atomic_cmpxchg(v, o, n) ((int)cmpxchg(&((v)->counter), (o), (n)))
79 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
81 #define atomic_add_unless(v, a, u) \
85 while (c != (u) && (old = atomic_cmpxchg((v), c, c + (a))) != c) \
89 #define atomic_inc_not_zero(v) atomic_add_unless((v), 1, 0)
91 static __inline__ void atomic_dec(volatile atomic_t * v)
95 local_irq_save(flags);
97 local_irq_restore(flags);
100 static __inline__ void atomic_clear_mask(unsigned int mask, atomic_t * v)
104 local_irq_save(flags);
106 local_irq_restore(flags);
109 static __inline__ void atomic_set_mask(unsigned int mask, atomic_t * v)
113 local_irq_save(flags);
115 local_irq_restore(flags);
118 /* Atomic operations are already serializing */
119 #define smp_mb__before_atomic_dec() barrier()
120 #define smp_mb__after_atomic_dec() barrier()
121 #define smp_mb__before_atomic_inc() barrier()
122 #define smp_mb__after_atomic_inc() barrier()
124 #define atomic_dec_return(v) atomic_sub_return(1,(v))
125 #define atomic_inc_return(v) atomic_add_return(1,(v))
128 * atomic_inc_and_test - increment and test
129 * @v: pointer of type atomic_t
131 * Atomically increments @v by 1
132 * and returns true if the result is zero, or false for all
135 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
137 #define atomic_sub_and_test(i,v) (atomic_sub_return((i), (v)) == 0)
138 #define atomic_dec_and_test(v) (atomic_sub_return(1, (v)) == 0)
140 #include <asm-generic/atomic.h>
142 #endif /* __ARCH_BLACKFIN_ATOMIC __ */