1 #ifndef __ASM_SH_ATOMIC_H
2 #define __ASM_SH_ATOMIC_H
5 * Atomic operations that C can't guarantee us. Useful for
6 * resource counting etc..
10 typedef struct { volatile int counter; } atomic_t;
12 #define ATOMIC_INIT(i) ( (atomic_t) { (i) } )
14 #define atomic_read(v) ((v)->counter)
15 #define atomic_set(v,i) ((v)->counter = (i))
17 #include <asm/system.h>
20 * To get proper branch prediction for the main line, we must branch
21 * forward to code at the end of this object's .text section, then
22 * branch back to restart the operation.
25 static __inline__ void atomic_add(int i, atomic_t * v)
29 local_irq_save(flags);
31 local_irq_restore(flags);
34 static __inline__ void atomic_sub(int i, atomic_t *v)
38 local_irq_save(flags);
40 local_irq_restore(flags);
43 static __inline__ int atomic_add_return(int i, atomic_t * v)
45 unsigned long temp, flags;
47 local_irq_save(flags);
51 local_irq_restore(flags);
56 #define atomic_add_negative(a, v) (atomic_add_return((a), (v)) < 0)
58 static __inline__ int atomic_sub_return(int i, atomic_t * v)
60 unsigned long temp, flags;
62 local_irq_save(flags);
66 local_irq_restore(flags);
71 #define atomic_dec_return(v) atomic_sub_return(1,(v))
72 #define atomic_inc_return(v) atomic_add_return(1,(v))
75 * atomic_inc_and_test - increment and test
76 * @v: pointer of type atomic_t
78 * Atomically increments @v by 1
79 * and returns true if the result is zero, or false for all
82 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
84 #define atomic_sub_and_test(i,v) (atomic_sub_return((i), (v)) == 0)
85 #define atomic_dec_and_test(v) (atomic_sub_return(1, (v)) == 0)
87 #define atomic_inc(v) atomic_add(1,(v))
88 #define atomic_dec(v) atomic_sub(1,(v))
90 static __inline__ void atomic_clear_mask(unsigned int mask, atomic_t *v)
94 local_irq_save(flags);
96 local_irq_restore(flags);
99 static __inline__ void atomic_set_mask(unsigned int mask, atomic_t *v)
103 local_irq_save(flags);
105 local_irq_restore(flags);
108 /* Atomic operations are already serializing on SH */
109 #define smp_mb__before_atomic_dec() barrier()
110 #define smp_mb__after_atomic_dec() barrier()
111 #define smp_mb__before_atomic_inc() barrier()
112 #define smp_mb__after_atomic_inc() barrier()
114 #endif /* __ASM_SH_ATOMIC_H */