2 * include/asm-v850/atomic.h -- Atomic operations
4 * Copyright (C) 2001,02 NEC Corporation
5 * Copyright (C) 2001,02 Miles Bader <miles@gnu.org>
7 * This file is subject to the terms and conditions of the GNU General
8 * Public License. See the file COPYING in the main directory of this
9 * archive for more details.
11 * Written by Miles Bader <miles@gnu.org>
14 #ifndef __V850_ATOMIC_H__
15 #define __V850_ATOMIC_H__
17 #include <linux/config.h>
19 #include <asm/system.h>
22 #error SMP not supported
25 typedef struct { int counter; } atomic_t;
27 #define ATOMIC_INIT(i) { (i) }
31 #define atomic_read(v) ((v)->counter)
32 #define atomic_set(v,i) (((v)->counter) = (i))
34 static inline int atomic_add_return (int i, volatile atomic_t *v)
39 local_irq_save (flags);
42 local_irq_restore (flags);
47 static __inline__ int atomic_sub_return (int i, volatile atomic_t *v)
52 local_irq_save (flags);
55 local_irq_restore (flags);
60 static __inline__ void atomic_clear_mask (unsigned long mask, unsigned long *addr)
64 local_irq_save (flags);
66 local_irq_restore (flags);
71 #define atomic_add(i, v) atomic_add_return ((i), (v))
72 #define atomic_sub(i, v) atomic_sub_return ((i), (v))
74 #define atomic_dec_return(v) atomic_sub_return (1, (v))
75 #define atomic_inc_return(v) atomic_add_return (1, (v))
76 #define atomic_inc(v) atomic_inc_return (v)
77 #define atomic_dec(v) atomic_dec_return (v)
80 * atomic_inc_and_test - increment and test
81 * @v: pointer of type atomic_t
83 * Atomically increments @v by 1
84 * and returns true if the result is zero, or false for all
87 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
89 #define atomic_sub_and_test(i,v) (atomic_sub_return ((i), (v)) == 0)
90 #define atomic_dec_and_test(v) (atomic_sub_return (1, (v)) == 0)
91 #define atomic_add_negative(i,v) (atomic_add_return ((i), (v)) < 0)
93 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
98 local_irq_save(flags);
100 if (likely(ret == old))
102 local_irq_restore(flags);
107 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
109 static inline int atomic_add_unless(atomic_t *v, int a, int u)
114 local_irq_save(flags);
118 local_irq_restore(flags);
123 #define atomic_inc_not_zero(v) atomic_add_unless((v), 1, 0)
125 /* Atomic operations are already serializing on ARM */
126 #define smp_mb__before_atomic_dec() barrier()
127 #define smp_mb__after_atomic_dec() barrier()
128 #define smp_mb__before_atomic_inc() barrier()
129 #define smp_mb__after_atomic_inc() barrier()
131 #include <asm-generic/atomic.h>
132 #endif /* __V850_ATOMIC_H__ */