aboutsummaryrefslogtreecommitdiffstats
path: root/include/asm-sh/atomic.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/asm-sh/atomic.h')
-rw-r--r--include/asm-sh/atomic.h32
1 files changed, 32 insertions, 0 deletions
diff --git a/include/asm-sh/atomic.h b/include/asm-sh/atomic.h
index 3c4f805da1ac..fb627de217f2 100644
--- a/include/asm-sh/atomic.h
+++ b/include/asm-sh/atomic.h
@@ -87,6 +87,37 @@ static __inline__ int atomic_sub_return(int i, atomic_t * v)
87#define atomic_inc(v) atomic_add(1,(v)) 87#define atomic_inc(v) atomic_add(1,(v))
88#define atomic_dec(v) atomic_sub(1,(v)) 88#define atomic_dec(v) atomic_sub(1,(v))
89 89
90static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
91{
92 int ret;
93 unsigned long flags;
94
95 local_irq_save(flags);
96 ret = v->counter;
97 if (likely(ret == old))
98 v->counter = new;
99 local_irq_restore(flags);
100
101 return ret;
102}
103
104#define atomic_xchg(v, new) (xchg(&((v)->counter), new))
105
106static inline int atomic_add_unless(atomic_t *v, int a, int u)
107{
108 int ret;
109 unsigned long flags;
110
111 local_irq_save(flags);
112 ret = v->counter;
113 if (ret != u)
114 v->counter += a;
115 local_irq_restore(flags);
116
117 return ret != u;
118}
119#define atomic_inc_not_zero(v) atomic_add_unless((v), 1, 0)
120
90static __inline__ void atomic_clear_mask(unsigned int mask, atomic_t *v) 121static __inline__ void atomic_clear_mask(unsigned int mask, atomic_t *v)
91{ 122{
92 unsigned long flags; 123 unsigned long flags;
@@ -111,4 +142,5 @@ static __inline__ void atomic_set_mask(unsigned int mask, atomic_t *v)
111#define smp_mb__before_atomic_inc() barrier() 142#define smp_mb__before_atomic_inc() barrier()
112#define smp_mb__after_atomic_inc() barrier() 143#define smp_mb__after_atomic_inc() barrier()
113 144
145#include <asm-generic/atomic.h>
114#endif /* __ASM_SH_ATOMIC_H */ 146#endif /* __ASM_SH_ATOMIC_H */