1 /* $Id: atomic.h,v 1.3 2001/07/25 16:15:19 bjornw Exp $ */
3 #ifndef __ASM_CRIS_ATOMIC__
4 #define __ASM_CRIS_ATOMIC__
6 #include <asm/system.h>
7 #include <asm/arch/atomic.h>
10 * Atomic operations that C can't guarantee us. Useful for
11 * resource counting etc..
14 typedef struct { volatile int counter; } atomic_t;
16 #define ATOMIC_INIT(i) { (i) }
18 #define atomic_read(v) ((v)->counter)
19 #define atomic_set(v,i) (((v)->counter) = (i))
21 /* These should be written in asm but we do it in C for now. */
23 extern __inline__ void atomic_add(int i, volatile atomic_t *v)
26 cris_atomic_save(v, flags);
28 cris_atomic_restore(v, flags);
31 extern __inline__ void atomic_sub(int i, volatile atomic_t *v)
34 cris_atomic_save(v, flags);
36 cris_atomic_restore(v, flags);
39 extern __inline__ int atomic_add_return(int i, volatile atomic_t *v)
43 cris_atomic_save(v, flags);
44 retval = (v->counter += i);
45 cris_atomic_restore(v, flags);
49 #define atomic_add_negative(a, v) (atomic_add_return((a), (v)) < 0)
51 extern __inline__ int atomic_sub_return(int i, volatile atomic_t *v)
55 cris_atomic_save(v, flags);
56 retval = (v->counter -= i);
57 cris_atomic_restore(v, flags);
61 extern __inline__ int atomic_sub_and_test(int i, volatile atomic_t *v)
65 cris_atomic_save(v, flags);
66 retval = (v->counter -= i) == 0;
67 cris_atomic_restore(v, flags);
71 extern __inline__ void atomic_inc(volatile atomic_t *v)
74 cris_atomic_save(v, flags);
76 cris_atomic_restore(v, flags);
79 extern __inline__ void atomic_dec(volatile atomic_t *v)
82 cris_atomic_save(v, flags);
84 cris_atomic_restore(v, flags);
87 extern __inline__ int atomic_inc_return(volatile atomic_t *v)
91 cris_atomic_save(v, flags);
92 retval = (v->counter)++;
93 cris_atomic_restore(v, flags);
97 extern __inline__ int atomic_dec_return(volatile atomic_t *v)
101 cris_atomic_save(v, flags);
102 retval = (v->counter)--;
103 cris_atomic_restore(v, flags);
106 extern __inline__ int atomic_dec_and_test(volatile atomic_t *v)
110 cris_atomic_save(v, flags);
111 retval = --(v->counter) == 0;
112 cris_atomic_restore(v, flags);
116 extern __inline__ int atomic_inc_and_test(volatile atomic_t *v)
120 cris_atomic_save(v, flags);
121 retval = ++(v->counter) == 0;
122 cris_atomic_restore(v, flags);
126 /* Atomic operations are already serializing */
127 #define smp_mb__before_atomic_dec() barrier()
128 #define smp_mb__after_atomic_dec() barrier()
129 #define smp_mb__before_atomic_inc() barrier()
130 #define smp_mb__after_atomic_inc() barrier()