1 #ifndef __ARCH_M68K_ATOMIC__
2 #define __ARCH_M68K_ATOMIC__
5 * Atomic operations that C can't guarantee us. Useful for
6 * resource counting etc..
10 * We do not have SMP m68k systems, so we don't have to deal with that.
13 typedef struct { int counter; } atomic_t;
14 #define ATOMIC_INIT(i) { (i) }
16 #define atomic_read(v) ((v)->counter)
17 #define atomic_set(v, i) (((v)->counter) = i)
19 static __inline__ void atomic_add(int i, atomic_t *v)
21 __asm__ __volatile__("addl %1,%0" : "=m" (*v) : "id" (i), "0" (*v));
24 static __inline__ void atomic_sub(int i, atomic_t *v)
26 __asm__ __volatile__("subl %1,%0" : "=m" (*v) : "id" (i), "0" (*v));
29 static __inline__ void atomic_inc(volatile atomic_t *v)
31 __asm__ __volatile__("addql #1,%0" : "=m" (*v): "0" (*v));
34 static __inline__ void atomic_dec(volatile atomic_t *v)
36 __asm__ __volatile__("subql #1,%0" : "=m" (*v): "0" (*v));
39 static __inline__ int atomic_dec_and_test(volatile atomic_t *v)
42 __asm__ __volatile__("subql #1,%1; seq %0" : "=d" (c), "=m" (*v): "1" (*v));
46 #define atomic_clear_mask(mask, v) \
47 __asm__ __volatile__("andl %1,%0" : "=m" (*v) : "id" (~(mask)),"0"(*v))
49 #define atomic_set_mask(mask, v) \
50 __asm__ __volatile__("orl %1,%0" : "=m" (*v) : "id" (mask),"0"(*v))
52 /* Atomic operations are already serializing */
53 #define smp_mb__before_atomic_dec() barrier()
54 #define smp_mb__after_atomic_dec() barrier()
55 #define smp_mb__before_atomic_inc() barrier()
56 #define smp_mb__after_atomic_inc() barrier()
58 #endif /* __ARCH_M68K_ATOMIC __ */