csutil/threading/atomicops.h Source File (Crystal Space 2.0 Public API Reference)

| ## Public API Reference

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

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 (const int32* target)
    00106     {
    00107       return Impl::CompareAndSet (const_cast<int32*> (target), 0, 0);
    00108     }
    00109
    00113     CS_FORCEINLINE_TEMPLATEMETHOD
    00114     static void* Read (void* const* target)
    00115     {
    00116       return Impl::CompareAndSet (
    00117         const_cast<void**> (target), (void*)0, (void*)0);
    00118     }
    00119   };
    00120 }
    00121 }
    00122
    00123 #if defined (CS_PLATFORM_WIN32) && \
    00124     defined (CS_COMPILER_MSVC)
    00125
    00126   #include "csutil/threading/atomicops_msvc.h"
    00127
    00128   namespace CS { namespace Threading {
    00129     typedef AtomicOperationsBase<AtomicOperationsMSVC> AtomicOperations;
    00130   } }
    00131
    00132 #elif defined(CS_COMPILER_GCC) && \
    00133       defined(CS_PROCESSOR_X86)
    00134
    00135   #include "csutil/threading/atomicops_gcc_x86.h"
    00136
    00137   namespace CS { namespace Threading {
    00138     typedef AtomicOperationsBase<AtomicOperationsX86GCC> AtomicOperations;
    00139   } }
    00140
    00141 #elif defined(CS_COMPILER_GCC) && \
    00142       defined(CS_PROCESSOR_POWERPC)
    00143
    00144   #include "csutil/threading/atomicops_gcc_ppc.h"
    00145
    00146   namespace CS { namespace Threading {
    00147     typedef AtomicOperationsBase<AtomicOperationsPPCGCC> AtomicOperations;
    00148   } }
    00149
    00150 #elif defined(CS_COMPILER_GCC) && \
    00151       defined(CS_PROCESSOR_SPARC)
    00152
    00153   #include "csutil/threading/atomicops_sparc.h"
    00154
    00155   namespace CS { namespace Threading {
    00156     typedef AtomicOperationsBase<AtomicOperationsSparc> AtomicOperations;
    00157   } }
    00158
    00159 #elif defined(CS_COMPILER_GCC) && \
    00160       defined(CS_PROCESSOR_ARM)
    00161   #include "csutil/threading/atomicops_gcc_arm.h"
    00162
    00163   namespace CS { namespace Threading {
    00164     typedef AtomicOperationsBase<AtomicOperationsArmGCC> AtomicOperations;
    00165   } }
    00166
    00167 #elif defined(CS_COMPILER_GCC)
    00168   #include "csutil/threading/atomicops_gcc_generic.h"
    00169
    00170   namespace CS { namespace Threading {
    00171     typedef AtomicOperationsBase<AtomicOperationsGenericGCC> AtomicOperations;
    00172   } }
    00173
    00174 #else
    00175 #error "No atomic operations defined for your platform!"
    00176 #endif
    00177
    00178 #endif