| 135 | |
| 136 | template <class T> |
| 137 | inline T* DoCas(T* volatile* target, T* exchange, T* compare) { |
| 138 | #if defined(__has_builtin) && __has_builtin(__sync_val_compare_and_swap) |
| 139 | return __sync_val_compare_and_swap(target, compare, exchange); |
| 140 | #elif defined(_WIN32) |
| 141 | #ifdef _64_ |
| 142 | return (T*)_InterlockedCompareExchange64((__int64*)target, (__int64)exchange, (__int64)compare); |
| 143 | #else |
| 144 | //return (T*)InterlockedCompareExchangePointer(targetVoidP, exchange, compare); |
| 145 | return (T*)_InterlockedCompareExchange((LONG*)target, (LONG)exchange, (LONG)compare); |
| 146 | #endif |
| 147 | #elif defined(__i386) || defined(__x86_64__) |
| 148 | union { |
| 149 | T* volatile* NP; |
| 150 | void* volatile* VoidP; |
| 151 | } gccSucks; |
| 152 | gccSucks.NP = target; |
| 153 | void* volatile* targetVoidP = gccSucks.VoidP; |
| 154 | |
| 155 | __asm__ __volatile__( |
| 156 | "lock\n\t" |
| 157 | "cmpxchg %2,%0\n\t" |
| 158 | : "+m"(*(targetVoidP)), "+a"(compare) |
| 159 | : "r"(exchange) |
| 160 | : "cc", "memory"); |
| 161 | return compare; |
| 162 | #else |
| 163 | #error inline_cas not defined for this platform |
| 164 | #endif |
| 165 | } |
| 166 | |
| 167 | #ifdef _64_ |
| 168 | const uintptr_t N_MAX_WORKSET_SIZE = 0x100000000ll * 200; |
no outgoing calls
no test coverage detected