00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef __CS_CSUTIL_ATOMICOPS_MSVC_H__
00020 #define __CS_CSUTIL_ATOMICOPS_MSVC_H__
00021
00022 #ifndef DOXYGEN_RUN
00023
00024 namespace CS
00025 {
00026 namespace Threading
00027 {
00028
00029 #pragma warning(push)
00030 #pragma warning(disable: 4311)
00031
00032
00033 class AtomicOperationsMSVC
00034 {
00035 public:
00036 inline static int32 Set (int32* target, int32 value)
00037 {
00038 return (int32)_InterlockedExchange ((long*)target, value);
00039 }
00040
00041 inline static void* Set (void** target, void* value)
00042 {
00043 #if CS_PROCESSOR_SIZE == 64
00044 return (void*)_InterlockedExchange64 ((__int64*)target, (__int64)value);
00045 #else
00046 return (void*)_InterlockedExchange ((long*)target, (long)value);
00047 #endif
00048 }
00049
00050 inline static int32 CompareAndSet (int32* target, int32 value,
00051 int32 comparand)
00052 {
00053 return (int32)_InterlockedCompareExchange ((long*)target,
00054 (long)value, (long)comparand);
00055 }
00056
00057 inline static void* CompareAndSet (void** target, void* value,
00058 void* comparand)
00059 {
00060 #if CS_PROCESSOR_SIZE == 64
00061 return (void*)_InterlockedCompareExchange64 ((__int64*)target,
00062 (__int64)value, (__int64)comparand);
00063 #else
00064 return (void*)_InterlockedCompareExchange ((long*)target,
00065 (long)value, (long)comparand);
00066 #endif
00067 }
00068
00069 inline static int32 Increment (int32* target)
00070 {
00071 return (int32)_InterlockedIncrement ((long*)target);
00072 }
00073
00074 inline static int32 Decrement (int32* target)
00075 {
00076 return (int32)_InterlockedDecrement ((long*)target);
00077 }
00078 };
00079 #pragma warning(pop)
00080
00081 }
00082 }
00083
00084 #endif // DOXYGEN_RUN
00085
00086 #endif // __CS_CSUTIL_ATOMICOPS_MSVC_H__