Warning, file /include/opencascade/Standard_Atomic.hxx was not indexed
or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027 #ifndef _Standard_Atomic_HeaderFile
0028 #define _Standard_Atomic_HeaderFile
0029
0030
0031
0032 inline int Standard_Atomic_Increment (volatile int* theValue);
0033
0034
0035
0036 inline int Standard_Atomic_Decrement (volatile int* theValue);
0037
0038
0039
0040
0041
0042
0043
0044 inline bool Standard_Atomic_CompareAndSwap (volatile int* theValue, int theOldValue, int theNewValue);
0045
0046
0047 #if defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4) || defined(__EMSCRIPTEN__)
0048
0049
0050
0051
0052
0053
0054
0055
0056 int Standard_Atomic_Increment (volatile int* theValue)
0057 {
0058 return __sync_add_and_fetch (theValue, 1);
0059 }
0060
0061 int Standard_Atomic_Decrement (volatile int* theValue)
0062 {
0063 return __sync_sub_and_fetch (theValue, 1);
0064 }
0065
0066 bool Standard_Atomic_CompareAndSwap (volatile int* theValue, int theOldValue, int theNewValue)
0067 {
0068 return __sync_val_compare_and_swap (theValue, theOldValue, theNewValue) == theOldValue;
0069 }
0070
0071 #elif defined(_WIN32)
0072 extern "C" {
0073 long _InterlockedIncrement (volatile long* lpAddend);
0074 long _InterlockedDecrement (volatile long* lpAddend);
0075 long _InterlockedCompareExchange (long volatile* Destination, long Exchange, long Comparand);
0076 }
0077
0078 #if defined(_MSC_VER) && ! defined(__INTEL_COMPILER)
0079
0080 #pragma intrinsic (_InterlockedIncrement)
0081 #pragma intrinsic (_InterlockedDecrement)
0082 #pragma intrinsic (_InterlockedCompareExchange)
0083 #endif
0084
0085
0086
0087
0088 int Standard_Atomic_Increment (volatile int* theValue)
0089 {
0090 return _InterlockedIncrement (reinterpret_cast<volatile long*>(theValue));
0091 }
0092
0093 int Standard_Atomic_Decrement (volatile int* theValue)
0094 {
0095 return _InterlockedDecrement (reinterpret_cast<volatile long*>(theValue));
0096 }
0097
0098 bool Standard_Atomic_CompareAndSwap (volatile int* theValue, int theOldValue, int theNewValue)
0099 {
0100 return _InterlockedCompareExchange (reinterpret_cast<volatile long*>(theValue), theNewValue, theOldValue) == theOldValue;
0101 }
0102
0103 #elif defined(__APPLE__)
0104
0105
0106 #include <libkern/OSAtomic.h>
0107
0108 int Standard_Atomic_Increment (volatile int* theValue)
0109 {
0110 return OSAtomicIncrement32Barrier (theValue);
0111 }
0112
0113 int Standard_Atomic_Decrement (volatile int* theValue)
0114 {
0115 return OSAtomicDecrement32Barrier (theValue);
0116 }
0117
0118 bool Standard_Atomic_CompareAndSwap (volatile int* theValue, int theOldValue, int theNewValue)
0119 {
0120 return OSAtomicCompareAndSwapInt (theOldValue, theNewValue, theValue);
0121 }
0122
0123 #elif defined(__ANDROID__)
0124
0125
0126
0127
0128
0129
0130 #include <sys/atomics.h>
0131
0132 int Standard_Atomic_Increment (volatile int* theValue)
0133 {
0134 return __atomic_inc (theValue) + 1;
0135 }
0136
0137 int Standard_Atomic_Decrement (volatile int* theValue)
0138 {
0139 return __atomic_dec (theValue) - 1;
0140 }
0141
0142 bool Standard_Atomic_CompareAndSwap (volatile int* theValue, int theOldValue, int theNewValue)
0143 {
0144 return __atomic_cmpxchg (theOldValue, theNewValue, theValue) == 0;
0145 }
0146
0147 #else
0148
0149 #ifndef IGNORE_NO_ATOMICS
0150 #error "Atomic operation isn't implemented for current platform!"
0151 #endif
0152 int Standard_Atomic_Increment (volatile int* theValue)
0153 {
0154 return ++(*theValue);
0155 }
0156
0157 int Standard_Atomic_Decrement (volatile int* theValue)
0158 {
0159 return --(*theValue);
0160 }
0161
0162 bool Standard_Atomic_CompareAndSwap (volatile int* theValue, int theOldValue, int theNewValue)
0163 {
0164 if (*theValue == theOldValue)
0165 {
0166 *theValue = theNewValue;
0167 return true;
0168 }
0169 return false;
0170 }
0171
0172 #endif
0173
0174 #endif