Sync AMTL from upstream
This commit is contained in:
@@ -38,9 +38,13 @@ namespace ke {
|
||||
extern "C" {
|
||||
long __cdecl _InterlockedIncrement(long volatile *dest);
|
||||
long __cdecl _InterlockedDecrement(long volatile *dest);
|
||||
long __cdecl _InterlockedIncrement64(long long volatile *dest);
|
||||
long __cdecl _InterlockedDecrement64(long long volatile *dest);
|
||||
}
|
||||
# pragma intrinsic(_InterlockedIncrement)
|
||||
# pragma intrinsic(_InterlockedDecrement)
|
||||
# pragma intrinsic(_InterlockedIncrement64)
|
||||
# pragma intrinsic(_InterlockedDecrement64)
|
||||
#endif
|
||||
|
||||
template <size_t Width>
|
||||
@@ -50,7 +54,7 @@ template <>
|
||||
struct AtomicOps<4>
|
||||
{
|
||||
#if defined(_MSC_VER)
|
||||
typedef long Type;
|
||||
typedef volatile long Type;
|
||||
|
||||
static Type Increment(Type *ptr) {
|
||||
return _InterlockedIncrement(ptr);
|
||||
@@ -59,7 +63,7 @@ struct AtomicOps<4>
|
||||
return _InterlockedDecrement(ptr);
|
||||
};
|
||||
#elif defined(__GNUC__)
|
||||
typedef int Type;
|
||||
typedef volatile int Type;
|
||||
|
||||
// x86/x64 notes: When using GCC < 4.8, this will compile to a spinlock.
|
||||
// On 4.8+, or when using Clang, we'll get the more optimal "lock addl"
|
||||
@@ -73,6 +77,34 @@ struct AtomicOps<4>
|
||||
#endif
|
||||
};
|
||||
|
||||
template <>
|
||||
struct AtomicOps<8>
|
||||
{
|
||||
#if defined(_MSC_VER)
|
||||
typedef volatile long long Type;
|
||||
|
||||
static Type Increment(Type *ptr) {
|
||||
return _InterlockedIncrement64(ptr);
|
||||
}
|
||||
static Type Decrement(Type *ptr) {
|
||||
return _InterlockedDecrement64(ptr);
|
||||
};
|
||||
#elif defined(__GNUC__)
|
||||
typedef volatile int64_t Type;
|
||||
|
||||
// x86/x64 notes: When using GCC < 4.8, this will compile to a spinlock.
|
||||
// On 4.8+, or when using Clang, we'll get the more optimal "lock addl"
|
||||
// variant.
|
||||
static Type Increment(Type *ptr) {
|
||||
return __sync_add_and_fetch(ptr, 1);
|
||||
}
|
||||
static Type Decrement(Type *ptr) {
|
||||
return __sync_sub_and_fetch(ptr, 1);
|
||||
}
|
||||
#endif
|
||||
};
|
||||
|
||||
|
||||
class AtomicRefCount
|
||||
{
|
||||
typedef AtomicOps<sizeof(uintptr_t)> Ops;
|
||||
|
||||
Reference in New Issue
Block a user