1 #ifndef __ARCH_BLACKFIN_ATOMIC__
2 #define __ARCH_BLACKFIN_ATOMIC__
4 #include <asm/system.h> /* local_irq_XXX() */
7 * Atomic operations that C can't guarantee us. Useful for
8 * resource counting etc..
10 * Generally we do not concern about SMP BFIN systems, so we don't have
13 * Tony Kou (tonyko@lineo.ca) Lineo Inc. 2001
19 #define ATOMIC_INIT(i) { (i) }
21 #define atomic_read(v) ((v)->counter)
22 #define atomic_set(v, i) (((v)->counter) = i)
24 static __inline__ void atomic_add(int i, atomic_t * v)
28 local_irq_save(flags);
30 local_irq_restore(flags);
33 static __inline__ void atomic_sub(int i, atomic_t * v)
37 local_irq_save(flags);
39 local_irq_restore(flags);
43 static inline int atomic_add_return(int i, atomic_t * v)
48 local_irq_save(flags);
51 local_irq_restore(flags);
57 #define atomic_add_negative(a, v) (atomic_add_return((a), (v)) < 0)
58 static inline int atomic_sub_return(int i, atomic_t * v)
63 local_irq_save(flags);
66 local_irq_restore(flags);
71 static __inline__ void atomic_inc(volatile atomic_t * v)
75 local_irq_save(flags);
77 local_irq_restore(flags);
80 #define atomic_cmpxchg(v, o, n) ((int)cmpxchg(&((v)->counter), (o), (n)))
81 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
83 #define atomic_add_unless(v, a, u) \
87 while (c != (u) && (old = atomic_cmpxchg((v), c, c + (a))) != c) \
91 #define atomic_inc_not_zero(v) atomic_add_unless((v), 1, 0)
93 static __inline__ void atomic_dec(volatile atomic_t * v)
97 local_irq_save(flags);
99 local_irq_restore(flags);
102 static __inline__ void atomic_clear_mask(unsigned int mask, atomic_t * v)
106 local_irq_save(flags);
108 local_irq_restore(flags);
111 static __inline__ void atomic_set_mask(unsigned int mask, atomic_t * v)
115 local_irq_save(flags);
117 local_irq_restore(flags);
120 /* Atomic operations are already serializing */
121 #define smp_mb__before_atomic_dec() barrier()
122 #define smp_mb__after_atomic_dec() barrier()
123 #define smp_mb__before_atomic_inc() barrier()
124 #define smp_mb__after_atomic_inc() barrier()
126 #define atomic_dec_return(v) atomic_sub_return(1,(v))
127 #define atomic_inc_return(v) atomic_add_return(1,(v))
130 * atomic_inc_and_test - increment and test
131 * @v: pointer of type atomic_t
133 * Atomically increments @v by 1
134 * and returns true if the result is zero, or false for all
137 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
139 #define atomic_sub_and_test(i,v) (atomic_sub_return((i), (v)) == 0)
140 #define atomic_dec_and_test(v) (atomic_sub_return(1, (v)) == 0)
142 #include <asm-generic/atomic.h>
144 #endif /* __ARCH_BLACKFIN_ATOMIC __ */