MCPcopy Create free account
hub / github.com/catboost/catboost / DoCas

Function DoCas

library/cpp/lfalloc/lf_allocX64.h:137–165  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

135
136template <class T>
137inline 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_
168const uintptr_t N_MAX_WORKSET_SIZE = 0x100000000ll * 200;

Callers 15

AllocWithMMapLinuxImplFunction · 0.70
LargeBlockAllocFunction · 0.70
FreeAllLargeBlockMemFunction · 0.70
LargeBlockFreeFunction · 0.70
TryLockMethod · 0.70
FutexWaitMethod · 0.70
UnlockMethod · 0.70
EnqueueMethod · 0.70
DoAllocMethod · 0.70
FreeListMethod · 0.70
AllocMethod · 0.70
GetWholeListMethod · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected