root/include/asm-alpha/atomic.h

/* [previous][next][first][last][top][bottom][index][help] */

INCLUDED FROM


DEFINITIONS

This source file includes following definitions.
  1. atomic_add
  2. atomic_sub
  3. atomic_sub_and_test

   1 #ifndef __ARCH_ALPHA_ATOMIC__
   2 #define __ARCH_ALPHA_ATOMIC__
   3 
   4 /*
   5  * Atomic operations that C can't guarantee us.  Useful for
   6  * resource counting etc...
   7  *
   8  * But use these as seldom as possible since they are much more slower
   9  * than regular operations.
  10  */
  11 
  12 /*
  13  * Make sure gcc doesn't try to be clever and move things around
  14  * on us. We need to use _exactly_ the address the user gave us,
  15  * not some alias that contains the same information.
  16  */
  17 #define __atomic_fool_gcc(x) (*(struct { int a[100]; } *)x)
  18 
  19 typedef int atomic_t;
  20 
  21 extern __inline__ void atomic_add(atomic_t i, atomic_t * v)
     /* [previous][next][first][last][top][bottom][index][help] */
  22 {
  23         unsigned long temp;
  24         __asm__ __volatile__(
  25                 "\n1:\t"
  26                 "ldl_l %0,%1\n\t"
  27                 "addl %0,%2,%0\n\t"
  28                 "stl_c %0,%1\n\t"
  29                 "beq %0,1b\n"
  30                 "2:"
  31                 :"=&r" (temp),
  32                  "=m" (__atomic_fool_gcc(v))
  33                 :"Ir" (i),
  34                  "m" (__atomic_fool_gcc(v)));
  35 }
  36 
  37 extern __inline__ void atomic_sub(atomic_t i, atomic_t * v)
     /* [previous][next][first][last][top][bottom][index][help] */
  38 {
  39         unsigned long temp;
  40         __asm__ __volatile__(
  41                 "\n1:\t"
  42                 "ldl_l %0,%1\n\t"
  43                 "subl %0,%2,%0\n\t"
  44                 "stl_c %0,%1\n\t"
  45                 "beq %0,1b\n"
  46                 "2:"
  47                 :"=&r" (temp),
  48                  "=m" (__atomic_fool_gcc(v))
  49                 :"Ir" (i),
  50                  "m" (__atomic_fool_gcc(v)));
  51 }
  52 
  53 /*
  54  * Same as above, but return true if we counted down to zero
  55  */
  56 extern __inline__ int atomic_sub_and_test(atomic_t i, atomic_t * v)
     /* [previous][next][first][last][top][bottom][index][help] */
  57 {
  58         unsigned long temp, result;
  59         __asm__ __volatile__(
  60                 "\n1:\t"
  61                 "ldl_l %0,%1\n\t"
  62                 "subl %0,%3,%0\n\t"
  63                 "bis %0,%0,%2\n\t"
  64                 "stl_c %0,%1\n\t"
  65                 "beq %0,1b\n"
  66                 "2:"
  67                 :"=&r" (temp),
  68                  "=m" (__atomic_fool_gcc(v)),
  69                  "=&r" (result)
  70                 :"Ir" (i),
  71                  "m" (__atomic_fool_gcc(v)));
  72         return result==0;
  73 }
  74 
  75 #define atomic_inc(v) atomic_add(1,(v))
  76 #define atomic_dec(v) atomic_sub(1,(v))
  77 #define atomic_dec_and_test(v) atomic_sub_and_test(1,(v))
  78 
  79 #endif

/* [previous][next][first][last][top][bottom][index][help] */