Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members

/home/jeroen/FOX/fox/fox-1.7.33/include/FXAtomic.h
00001 /********************************************************************************
00002 *                                                                               *
00003 *                         A t o m i c   O p e r a t i o n s                     *
00004 *                                                                               *
00005 *********************************************************************************
00006 * Copyright (C) 2006,2012 by Jeroen van der Zijp.   All Rights Reserved.        *
00007 *********************************************************************************
00008 * This library is free software; you can redistribute it and/or modify          *
00009 * it under the terms of the GNU Lesser General Public License as published by   *
00010 * the Free Software Foundation; either version 3 of the License, or             *
00011 * (at your option) any later version.                                           *
00012 *                                                                               *
00013 * This library is distributed in the hope that it will be useful,               *
00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of                *
00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                 *
00016 * GNU Lesser General Public License for more details.                           *
00017 *                                                                               *
00018 * You should have received a copy of the GNU Lesser General Public License      *
00019 * along with this program.  If not, see <http://www.gnu.org/licenses/>          *
00020 ********************************************************************************/
00021 #ifndef FXATOMIC_H
00022 #define FXATOMIC_H
00023 
00024 
00025 namespace FX {
00026 
00031 extern FXAPI FXbool atomicsAvailable();
00032 
00033 
00035 
00037 extern FXAPI FXint atomicSet(volatile FXint* ptr,FXint v);
00038 
00040 extern FXAPI FXint atomicAdd(volatile FXint* ptr,FXint v);
00041 
00043 extern FXAPI FXint atomicCas(volatile FXint* ptr,FXint expect,FXint v);
00044 
00046 extern FXAPI FXbool atomicBoolCas(volatile FXint* ptr,FXint expect,FXint v);
00047 
00048 
00050 
00052 extern FXAPI void* atomicSet(void* volatile* ptr,void* v);
00053 
00055 extern FXAPI void* atomicAdd(void* volatile* ptr,FXival v);
00056 
00058 extern FXAPI void* atomicCas(void* volatile* ptr,void* expect,void* v);
00059 
00061 extern FXAPI FXbool atomicBoolCas(void* volatile* ptr,void* expect,void* v);
00062 
00064 extern FXAPI FXbool atomicBoolDCas(void* volatile* ptr,void* cmpa,void* cmpb,void* a,void* b);
00065 
00066 
00068 
00070 template <class EType>
00071 inline EType* atomicSet(EType* volatile* ptr,EType* v){
00072   return (EType*)atomicSet((void*volatile*)ptr,(void*)v);
00073   }
00074 
00075 
00077 template <class EType>
00078 inline EType* atomicAdd(EType* volatile* ptr,FXival v){
00079   return (EType*)atomicAdd((void*volatile*)ptr,v*((FXival)sizeof(EType)));
00080   }
00081 
00082 
00084 template <class EType>
00085 inline EType* atomicCas(EType* volatile* ptr,EType* expect,EType* v){
00086   return (EType*)atomicCas((void*volatile*)ptr,(void*)expect,(void*)v);
00087   }
00088 
00089 
00091 template <class EType>
00092 inline FXbool atomicBoolCas(EType* volatile* ptr,EType* expect,EType* v){
00093   return atomicBoolCas((void*volatile*)ptr,(void*)expect,(void*)v);
00094   }
00095 
00096 
00098 template <class EType>
00099 inline FXbool atomicBoolDCas(EType* volatile* ptr,EType* cmpa,EType* cmpb,EType* a,EType* b){
00100   return atomicBoolDCas((void*volatile*)ptr,(void*)cmpa,(void*)cmpb,(void*)a,(void*)b);
00101   }
00102 
00103 
00104 }
00105 
00106 #endif

Copyright © 1997-2011 Jeroen van der Zijp