CrystalSpace

Public API Reference

csutil/threading/atomicops.h

Go to the documentation of this file.
00001 /*
00002   Copyright (C) 2006 by Marten Svanfeldt
00003 
00004   This library is free software; you can redistribute it and/or
00005   modify it under the terms of the GNU Lesser General Public
00006   License as published by the Free Software Foundation; either
00007   version 2 of the License, or (at your option) any later version.
00008 
00009   This library is distributed in the hope that it will be useful,
00010   but WITHOUT ANY WARRANTY; without even the implied warranty of
00011   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012   Library General Public License for more details.
00013 
00014   You should have received a copy of the GNU Library General Public
00015   License along with this library; if not, write to the Free
00016   Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00017 */
00018 
00019 #ifndef __CS_CSUTIL_ATOMICOPS_H__
00020 #define __CS_CSUTIL_ATOMICOPS_H__
00021 
00025 namespace CS
00026 {
00027 namespace Threading
00028 {
00029 
00035   template<typename Impl>
00036   class AtomicOperationsBase
00037   {
00038   public:
00042     CS_FORCEINLINE_TEMPLATEMETHOD
00043     static int32 Set (int32* target, int32 value)
00044     {
00045       return Impl::Set (target, value);
00046     }
00047 
00051     CS_FORCEINLINE_TEMPLATEMETHOD
00052     static void* Set ( void** target, void* value)
00053     {
00054       return Impl::Set (target, value);
00055     }
00056 
00062     CS_FORCEINLINE_TEMPLATEMETHOD
00063     static int32 CompareAndSet (int32* target, int32 value,
00064       int32 comparand)
00065     {
00066       return Impl::CompareAndSet (target, value, comparand);
00067     }
00068 
00074     CS_FORCEINLINE_TEMPLATEMETHOD
00075     static void* CompareAndSet (void** target, void* value,
00076       void* comparand)
00077     {
00078       return Impl::CompareAndSet (target, value, comparand);
00079     }
00080 
00085     CS_FORCEINLINE_TEMPLATEMETHOD
00086     static int32 Increment (int32* target)
00087     {
00088       return Impl::Increment (target);
00089     }
00090 
00095     CS_FORCEINLINE_TEMPLATEMETHOD
00096     static int32 Decrement (int32* target)
00097     {
00098       return Impl::Decrement (target);
00099     }
00100 
00104     CS_FORCEINLINE_TEMPLATEMETHOD
00105     static int32 Read (int32* target)
00106     {
00107       return Impl::CompareAndSet (target, 0, 0);
00108     }
00109 
00113     CS_FORCEINLINE_TEMPLATEMETHOD
00114     static void* Read (void** target)
00115     {
00116       return Impl::CompareAndSet (target, (void*)0, (void*)0);
00117     }
00118   };
00119 }
00120 }
00121 
00122 #if defined (CS_PLATFORM_WIN32) && \
00123     defined (CS_COMPILER_MSVC)
00124 
00125   #include "csutil/threading/atomicops_msvc.h"
00126 
00127   namespace CS { namespace Threading {
00128     typedef AtomicOperationsBase<AtomicOperationsMSVC> AtomicOperations;
00129   } }
00130 
00131 #elif defined(CS_COMPILER_GCC) && \
00132       defined(CS_PROCESSOR_X86)
00133   
00134   #include "csutil/threading/atomicops_gcc_x86.h"
00135 
00136   namespace CS { namespace Threading {
00137     typedef AtomicOperationsBase<AtomicOperationsX86GCC> AtomicOperations;
00138   } }
00139 
00140 #elif defined(CS_COMPILER_GCC) && \
00141       defined(CS_PROCESSOR_POWERPC)
00142   
00143   #include "csutil/threading/atomicops_gcc_ppc.h"
00144 
00145   namespace CS { namespace Threading {
00146     typedef AtomicOperationsBase<AtomicOperationsPPCGCC> AtomicOperations;
00147   } }
00148 
00149 #elif defined(CS_COMPILER_GCC) && \
00150       defined(CS_PROCESSOR_SPARC)
00151 
00152   #include "csutil/threading/atomicops_sparc.h"
00153 
00154   namespace CS { namespace Threading {
00155     typedef AtomicOperationsBase<AtomicOperationsSparc> AtomicOperations;
00156   } }
00157 
00158 #else
00159 #error "No atomic operations defined for your platform!"
00160 #endif
00161 
00162 #endif

Generated for Crystal Space 1.2.1 by doxygen 1.5.3