00001 #ifndef IG_PROF_IG_PROF_ATOMIC_H
00002 # define IG_PROF_IG_PROF_ATOMIC_H
00003
00004 # if __i386__ || __ppc__
00005 # else
00006 # error Sorry this platform is not supported.
00007 # endif
00008
00009
00010
00011
00012
00013
00014 typedef int IgProfAtomic;
00015
00016
00017
00018
00019
00020
00021 inline IgProfAtomic
00022 IgProfAtomicInc (volatile IgProfAtomic *val)
00023 {
00024 # if __i386__
00025 IgProfAtomic result;
00026 __asm__ __volatile__
00027 (" lock; xaddl %0, (%1); incl %0;"
00028 : "=r" (result)
00029 : "r" (val), "0" (1));
00030 return result+1;
00031 # elif __ppc__
00032 IgProfAtomic result;
00033 __asm__ __volatile__
00034 (" lwsync\n"
00035 "1: lwarx %0, 0, %1\n"
00036 " addic %0, %0, 1\n"
00037 " stwcx. %0, 0, %1\n"
00038 " bne- 1b\n"
00039 " isync\n"
00040 : "=&r" (result)
00041 : "r" (val)
00042 : "cc", "memory");
00043 return result;
00044 # endif
00045 }
00046
00047 inline IgProfAtomic
00048 IgProfAtomicDec (volatile IgProfAtomic *val)
00049 {
00050 # if __i386__
00051 IgProfAtomic result;
00052 __asm__ __volatile__
00053 ("lock; xaddl %0, (%1); decl %0;"
00054 : "=r" (result)
00055 : "r" (val), "0" (-1));
00056 return result;
00057 # elif __ppc__
00058 IgProfAtomic result;
00059 __asm__ __volatile__
00060 (" lwsync\n"
00061 "1: lwarx %0, 0, %1\n"
00062 " addic %0, %0, -1\n"
00063 " stwcx. %0, 0, %1\n"
00064 " bne- 1b\n"
00065 " isync\n"
00066 : "=&r" (result)
00067 : "r" (val)
00068 : "cc", "memory");
00069 return result;
00070 # endif
00071 }
00072
00073
00074
00075 #endif // IG_PROF_IG_PROF_ATOMIC_H