00001
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef ZYGOMA_IA32_ATOMIC_H_
00024 #define ZYGOMA_IA32_ATOMIC_H_
00025
00026 #include "config.h"
00027
00028 namespace Zygoma
00029 {
00030 namespace ia32
00031 {
00048 typedef int AtomicWord;
00049
00050
00060 ZYGOMA_ALWAYS_INLINE AtomicWord
00061 atomicExchange(volatile AtomicWord* mem, int value)
00062 {
00063 register AtomicWord result;
00064 ZYGOMA_ASM("xchg{l} %[mem], %[result]"
00065 : [result] "=&r" (result), [mem] "=m" (*mem)
00066 : "0" (value)
00067 : "memory");
00068 return result;
00069 }
00070
00071
00080 ZYGOMA_ALWAYS_INLINE AtomicWord
00081 atomicExchangeAndAdd(volatile AtomicWord* mem, int value)
00082 {
00083 register AtomicWord result;
00084 ZYGOMA_ASM("lock xadd{l} %[result], %[mem]"
00085 : [result] "=&r" (result), [mem] "=m" (*mem)
00086 :"0" (value)
00087 : "memory");
00088 return result;
00089 }
00090
00091
00099 ZYGOMA_ALWAYS_INLINE void
00100 atomicAdd(volatile AtomicWord* mem, int value)
00101 {
00102 ZYGOMA_ASM("lock add{l} %[value],%[mem]"
00103 : [mem] "=m" (*mem)
00104 : [value] "ir" (value)
00105 : "memory");
00106 }
00107
00109 }
00110 }
00111
00112 #endif // ZYGOMA_IA32_ATOMIC_H_