root/include/asm-m68k/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_inc
  4. atomic_dec
  5. atomic_dec_and_test

   1 #ifndef __ARCH_M68K_ATOMIC__
   2 #define __ARCH_M68K_ATOMIC__
   3 
   4 /*
   5  * Atomic operations that C can't guarantee us.  Useful for
   6  * resource counting etc..
   7  */
   8 
   9 /*
  10  * We do not have SMP m68k systems, so we don't have to deal with that.
  11  */
  12 
  13 /*
  14  * Make sure gcc doesn't try to be clever and move things around
  15  * on us. We need to use _exactly_ the address the user gave us,
  16  * not some alias that contains the same information.
  17  */
  18 #define __atomic_fool_gcc(x) (*(struct { int a[100]; } *)x)
  19 
  20 typedef int atomic_t;
  21 
  22 static __inline__ void atomic_add(atomic_t i, atomic_t *v)
     /* [previous][next][first][last][top][bottom][index][help] */
  23 {
  24         __asm__ __volatile__(
  25                 "addl %1,%0"
  26                 :"=m" (__atomic_fool_gcc(v))
  27                 :"ir" (i), "m" (__atomic_fool_gcc(v)));
  28 }
  29 
  30 static __inline__ void atomic_sub(atomic_t i, atomic_t *v)
     /* [previous][next][first][last][top][bottom][index][help] */
  31 {
  32         __asm__ __volatile__(
  33                 "subl  %1,%0"
  34                 :"=m" (__atomic_fool_gcc(v))
  35                 :"ir" (i), "m" (__atomic_fool_gcc(v)));
  36 }
  37 
  38 static __inline__ void atomic_inc(atomic_t *v)
     /* [previous][next][first][last][top][bottom][index][help] */
  39 {
  40         __asm__ __volatile__(
  41                 "addql #1,%0"
  42                 :"=m" (__atomic_fool_gcc(v))
  43                 :"m" (__atomic_fool_gcc(v)));
  44 }
  45 
  46 static __inline__ void atomic_dec(atomic_t *v)
     /* [previous][next][first][last][top][bottom][index][help] */
  47 {
  48         __asm__ __volatile__(
  49                 "subql #1,%0"
  50                 :"=m" (__atomic_fool_gcc(v))
  51                 :"m" (__atomic_fool_gcc(v)));
  52 }
  53 
  54 static __inline__ int atomic_dec_and_test(atomic_t *v)
     /* [previous][next][first][last][top][bottom][index][help] */
  55 {
  56         __asm__ __volatile__(
  57                 "subql #1,%0"
  58                 :"=m" (__atomic_fool_gcc(v))
  59                 :"m" (__atomic_fool_gcc(v)));
  60         return (*v <= 0);
  61 }
  62 
  63 #endif /* __ARCH_M68K_ATOMIC __ */

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