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

TOMOYO Linux Cross Reference
Linux/arch/alpha/include/asm/local.h

Version: ~ [ linux-5.4-rc3 ] ~ [ linux-5.3.6 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.79 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.149 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.196 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.196 ] ~ [ 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.75 ] ~ [ 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 _ALPHA_LOCAL_H
  2 #define _ALPHA_LOCAL_H
  3 
  4 #include <linux/percpu.h>
  5 #include <linux/atomic.h>
  6 
  7 typedef struct
  8 {
  9         atomic_long_t a;
 10 } local_t;
 11 
 12 #define LOCAL_INIT(i)   { ATOMIC_LONG_INIT(i) }
 13 #define local_read(l)   atomic_long_read(&(l)->a)
 14 #define local_set(l,i)  atomic_long_set(&(l)->a, (i))
 15 #define local_inc(l)    atomic_long_inc(&(l)->a)
 16 #define local_dec(l)    atomic_long_dec(&(l)->a)
 17 #define local_add(i,l)  atomic_long_add((i),(&(l)->a))
 18 #define local_sub(i,l)  atomic_long_sub((i),(&(l)->a))
 19 
 20 static __inline__ long local_add_return(long i, local_t * l)
 21 {
 22         long temp, result;
 23         __asm__ __volatile__(
 24         "1:     ldq_l %0,%1\n"
 25         "       addq %0,%3,%2\n"
 26         "       addq %0,%3,%0\n"
 27         "       stq_c %0,%1\n"
 28         "       beq %0,2f\n"
 29         ".subsection 2\n"
 30         "2:     br 1b\n"
 31         ".previous"
 32         :"=&r" (temp), "=m" (l->a.counter), "=&r" (result)
 33         :"Ir" (i), "m" (l->a.counter) : "memory");
 34         return result;
 35 }
 36 
 37 static __inline__ long local_sub_return(long i, local_t * l)
 38 {
 39         long temp, result;
 40         __asm__ __volatile__(
 41         "1:     ldq_l %0,%1\n"
 42         "       subq %0,%3,%2\n"
 43         "       subq %0,%3,%0\n"
 44         "       stq_c %0,%1\n"
 45         "       beq %0,2f\n"
 46         ".subsection 2\n"
 47         "2:     br 1b\n"
 48         ".previous"
 49         :"=&r" (temp), "=m" (l->a.counter), "=&r" (result)
 50         :"Ir" (i), "m" (l->a.counter) : "memory");
 51         return result;
 52 }
 53 
 54 #define local_cmpxchg(l, o, n) \
 55         (cmpxchg_local(&((l)->a.counter), (o), (n)))
 56 #define local_xchg(l, n) (xchg_local(&((l)->a.counter), (n)))
 57 
 58 /**
 59  * local_add_unless - add unless the number is a given value
 60  * @l: pointer of type local_t
 61  * @a: the amount to add to l...
 62  * @u: ...unless l is equal to u.
 63  *
 64  * Atomically adds @a to @l, so long as it was not @u.
 65  * Returns non-zero if @l was not @u, and zero otherwise.
 66  */
 67 #define local_add_unless(l, a, u)                               \
 68 ({                                                              \
 69         long c, old;                                            \
 70         c = local_read(l);                                      \
 71         for (;;) {                                              \
 72                 if (unlikely(c == (u)))                         \
 73                         break;                                  \
 74                 old = local_cmpxchg((l), c, c + (a));   \
 75                 if (likely(old == c))                           \
 76                         break;                                  \
 77                 c = old;                                        \
 78         }                                                       \
 79         c != (u);                                               \
 80 })
 81 #define local_inc_not_zero(l) local_add_unless((l), 1, 0)
 82 
 83 #define local_add_negative(a, l) (local_add_return((a), (l)) < 0)
 84 
 85 #define local_dec_return(l) local_sub_return(1,(l))
 86 
 87 #define local_inc_return(l) local_add_return(1,(l))
 88 
 89 #define local_sub_and_test(i,l) (local_sub_return((i), (l)) == 0)
 90 
 91 #define local_inc_and_test(l) (local_add_return(1, (l)) == 0)
 92 
 93 #define local_dec_and_test(l) (local_sub_return(1, (l)) == 0)
 94 
 95 /* Verify if faster than atomic ops */
 96 #define __local_inc(l)          ((l)->a.counter++)
 97 #define __local_dec(l)          ((l)->a.counter++)
 98 #define __local_add(i,l)        ((l)->a.counter+=(i))
 99 #define __local_sub(i,l)        ((l)->a.counter-=(i))
100 
101 #endif /* _ALPHA_LOCAL_H */
102 

~ [ 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