Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

arch/ia32/include/atomic.h

Go to the documentation of this file.
00001 
00007 /*
00008  *  Copyright (C) 2003 Bregmasoft
00009  * 
00010  * This program is free software; you can redistribute it and/or modify it under
00011  * the terms of the GNU General Public License as published by the Free Software
00012  * Foundation; either version 2 of the License, or (at your option) any later
00013  * version.
00014  * 
00015  * This program is distributed in the hope that it will be useful, but WITHOUT ANY
00016  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
00017  * PARTICULAR PURPOSE. See the GNU General Public License for more details.
00018  * 
00019  * You should have received a copy of the GNU General Public License along with
00020  * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
00021  * Place, Suite 330, Boston, MA 02111-1307 USA
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   } // namespace ia32
00110 } // namespace Zygoma
00111 
00112 #endif // ZYGOMA_IA32_ATOMIC_H_ 

Generated on Fri Sep 2 10:44:36 2005 for zygoma by doxygen 1.4.2