1 #ifndef __ARCH_M68KNOMMU_ATOMIC__
2 #define __ARCH_M68KNOMMU_ATOMIC__
4 #include <asm/system.h> /* local_irq_XXX() */
7 * Atomic operations that C can't guarantee us. Useful for
8 * resource counting etc..
12 * We do not have SMP m68k systems, so we don't have to deal with that.
15 typedef struct { 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 static __inline__ void atomic_add(int i, atomic_t *v)
23 __asm__ __volatile__("addl %1,%0" : "=m" (*v) : "d" (i), "0" (*v));
26 static __inline__ void atomic_sub(int i, atomic_t *v)
28 __asm__ __volatile__("subl %1,%0" : "=m" (*v) : "d" (i), "0" (*v));
31 static __inline__ void atomic_inc(volatile atomic_t *v)
33 __asm__ __volatile__("addql #1,%0" : "=m" (*v): "0" (*v));
36 static __inline__ void atomic_dec(volatile atomic_t *v)
38 __asm__ __volatile__("subql #1,%0" : "=m" (*v): "0" (*v));
41 static __inline__ int atomic_dec_and_test(volatile atomic_t *v)
44 __asm__ __volatile__("subql #1,%1; seq %0" : "=d" (c), "=m" (*v): "1" (*v));
48 #define atomic_clear_mask(mask, v) \
49 __asm__ __volatile__("andl %1,%0" : "=m" (*v) : "id" (~(mask)),"0"(*v))
51 #define atomic_set_mask(mask, v) \
52 __asm__ __volatile__("orl %1,%0" : "=m" (*v) : "id" (mask),"0"(*v))
54 /* Atomic operations are already serializing */
55 #define smp_mb__before_atomic_dec() barrier()
56 #define smp_mb__after_atomic_dec() barrier()
57 #define smp_mb__before_atomic_inc() barrier()
58 #define smp_mb__after_atomic_inc() barrier()
60 extern __inline__ int atomic_add_return(int i, atomic_t * v)
62 unsigned long temp, flags;
64 local_irq_save(flags);
68 local_irq_restore(flags);
73 #define atomic_add_negative(a, v) (atomic_add_return((a), (v)) < 0)
75 extern __inline__ int atomic_sub_return(int i, atomic_t * v)
77 unsigned long temp, flags;
79 local_irq_save(flags);
83 local_irq_restore(flags);
88 #define atomic_dec_return(v) atomic_sub_return(1,(v))
89 #define atomic_inc_return(v) atomic_add_return(1,(v))
92 * atomic_inc_and_test - increment and test
93 * @v: pointer of type atomic_t
95 * Atomically increments @v by 1
96 * and returns true if the result is zero, or false for all
99 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
101 #define atomic_sub_and_test(i,v) (atomic_sub_return((i), (v)) == 0)
102 #define atomic_dec_and_test(v) (atomic_sub_return(1, (v)) == 0)
104 #endif /* __ARCH_M68KNOMMU_ATOMIC __ */