~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/arch/h8300/include/asm/atomic.h

Version: ~ [ linux-5.3-rc5 ] ~ [ linux-5.2.9 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.67 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.139 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.189 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.189 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.19.8 ] ~ [ linux-3.18.140 ] ~ [ linux-3.17.8 ] ~ [ linux-3.16.72 ] ~ [ linux-3.15.10 ] ~ [ linux-3.14.79 ] ~ [ linux-3.13.11 ] ~ [ linux-3.12.74 ] ~ [ linux-3.11.10 ] ~ [ linux-3.10.108 ] ~ [ linux-3.9.11 ] ~ [ linux-3.8.13 ] ~ [ linux-3.7.10 ] ~ [ linux-3.6.11 ] ~ [ linux-3.5.7 ] ~ [ linux-3.4.113 ] ~ [ linux-3.3.8 ] ~ [ linux-3.2.102 ] ~ [ linux-3.1.10 ] ~ [ linux-3.0.101 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 #ifndef __ARCH_H8300_ATOMIC__
  2 #define __ARCH_H8300_ATOMIC__
  3 
  4 #include <linux/types.h>
  5 
  6 /*
  7  * Atomic operations that C can't guarantee us.  Useful for
  8  * resource counting etc..
  9  */
 10 
 11 #define ATOMIC_INIT(i)  { (i) }
 12 
 13 #define atomic_read(v)          (*(volatile int *)&(v)->counter)
 14 #define atomic_set(v, i)        (((v)->counter) = i)
 15 
 16 #include <asm/system.h>
 17 #include <linux/kernel.h>
 18 
 19 static __inline__ int atomic_add_return(int i, atomic_t *v)
 20 {
 21         unsigned long flags;
 22         int ret;
 23         local_irq_save(flags);
 24         ret = v->counter += i;
 25         local_irq_restore(flags);
 26         return ret;
 27 }
 28 
 29 #define atomic_add(i, v) atomic_add_return(i, v)
 30 #define atomic_add_negative(a, v)       (atomic_add_return((a), (v)) < 0)
 31 
 32 static __inline__ int atomic_sub_return(int i, atomic_t *v)
 33 {
 34         unsigned long flags;
 35         int ret;
 36         local_irq_save(flags);
 37         ret = v->counter -= i;
 38         local_irq_restore(flags);
 39         return ret;
 40 }
 41 
 42 #define atomic_sub(i, v) atomic_sub_return(i, v)
 43 #define atomic_sub_and_test(i,v) (atomic_sub_return(i, v) == 0)
 44 
 45 static __inline__ int atomic_inc_return(atomic_t *v)
 46 {
 47         unsigned long flags;
 48         int ret;
 49         local_irq_save(flags);
 50         v->counter++;
 51         ret = v->counter;
 52         local_irq_restore(flags);
 53         return ret;
 54 }
 55 
 56 #define atomic_inc(v) atomic_inc_return(v)
 57 
 58 /*
 59  * atomic_inc_and_test - increment and test
 60  * @v: pointer of type atomic_t
 61  *
 62  * Atomically increments @v by 1
 63  * and returns true if the result is zero, or false for all
 64  * other cases.
 65  */
 66 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
 67 
 68 static __inline__ int atomic_dec_return(atomic_t *v)
 69 {
 70         unsigned long flags;
 71         int ret;
 72         local_irq_save(flags);
 73         --v->counter;
 74         ret = v->counter;
 75         local_irq_restore(flags);
 76         return ret;
 77 }
 78 
 79 #define atomic_dec(v) atomic_dec_return(v)
 80 
 81 static __inline__ int atomic_dec_and_test(atomic_t *v)
 82 {
 83         unsigned long flags;
 84         int ret;
 85         local_irq_save(flags);
 86         --v->counter;
 87         ret = v->counter;
 88         local_irq_restore(flags);
 89         return ret == 0;
 90 }
 91 
 92 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
 93 {
 94         int ret;
 95         unsigned long flags;
 96 
 97         local_irq_save(flags);
 98         ret = v->counter;
 99         if (likely(ret == old))
100                 v->counter = new;
101         local_irq_restore(flags);
102         return ret;
103 }
104 
105 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
106 
107 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
108 {
109         int ret;
110         unsigned long flags;
111 
112         local_irq_save(flags);
113         ret = v->counter;
114         if (ret != u)
115                 v->counter += a;
116         local_irq_restore(flags);
117         return ret;
118 }
119 
120 static __inline__ void atomic_clear_mask(unsigned long mask, unsigned long *v)
121 {
122         __asm__ __volatile__("stc ccr,r1l\n\t"
123                              "orc #0x80,ccr\n\t"
124                              "mov.l %0,er0\n\t"
125                              "and.l %1,er0\n\t"
126                              "mov.l er0,%0\n\t"
127                              "ldc r1l,ccr" 
128                              : "=m" (*v) : "g" (~(mask)) :"er0","er1");
129 }
130 
131 static __inline__ void atomic_set_mask(unsigned long mask, unsigned long *v)
132 {
133         __asm__ __volatile__("stc ccr,r1l\n\t"
134                              "orc #0x80,ccr\n\t"
135                              "mov.l %0,er0\n\t"
136                              "or.l %1,er0\n\t"
137                              "mov.l er0,%0\n\t"
138                              "ldc r1l,ccr" 
139                              : "=m" (*v) : "g" (mask) :"er0","er1");
140 }
141 
142 /* Atomic operations are already serializing */
143 #define smp_mb__before_atomic_dec()    barrier()
144 #define smp_mb__after_atomic_dec() barrier()
145 #define smp_mb__before_atomic_inc()    barrier()
146 #define smp_mb__after_atomic_inc() barrier()
147 
148 #endif /* __ARCH_H8300_ATOMIC __ */
149 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp