namespace sys {
void MemoryFence();
- typedef uint32_t cas_flag;
- cas_flag CompareAndSwap(volatile cas_flag* ptr,
- cas_flag new_value,
- cas_flag old_value);
- cas_flag AtomicIncrement(volatile cas_flag* ptr);
- cas_flag AtomicDecrement(volatile cas_flag* ptr);
- cas_flag AtomicAdd(volatile cas_flag* ptr, cas_flag val);
+ uint32_t CompareAndSwap32(volatile uint32_t* ptr,
+ uint32_t new_value,
+ uint32_t old_value);
+ uint32_t AtomicIncrement32(volatile uint32_t* ptr);
+ uint32_t AtomicDecrement32(volatile uint32_t* ptr);
+ uint32_t AtomicAdd32(volatile uint32_t* ptr, uint32_t val);
+
+ uint64_t AtomicAdd64(volatile uint64_t* ptr, uint64_t val);
}
}
/// has no AbstractTypeUsers, the type is deleted. This is only sensical for
/// derived types.
///
- mutable sys::cas_flag RefCount;
+ mutable uint32_t RefCount;
const Type *getForwardedTypeInternal() const;
void addRef() const {
assert(isAbstract() && "Cannot add a reference to a non-abstract type!");
- sys::AtomicIncrement(&RefCount);
+ sys::AtomicIncrement32(&RefCount);
}
void dropRef() const {
// If this is the last PATypeHolder using this object, and there are no
// PATypeHandles using it, the type is dead, delete it now.
- sys::cas_flag OldCount = sys::AtomicDecrement(&RefCount);
- if (OldCount == 0 && AbstractTypeUsers.empty())
+ uint32_t Count = sys::AtomicDecrement32(&RefCount);
+ if (Count == 0 && AbstractTypeUsers.empty())
this->destroy();
}
#endif
}
-sys::cas_flag sys::CompareAndSwap(volatile sys::cas_flag* ptr,
- sys::cas_flag new_value,
- sys::cas_flag old_value) {
+uint32_t sys::CompareAndSwap32(volatile uint32_t* ptr,
+ uint32_t new_value,
+ uint32_t old_value) {
#if LLVM_MULTITHREADED==0
- sys::cas_flag result = *ptr;
+ uint32_t result = *ptr;
if (result == old_value)
*ptr = new_value;
return result;
#endif
}
-sys::cas_flag sys::AtomicIncrement(volatile sys::cas_flag* ptr) {
+uint32_t sys::AtomicIncrement32(volatile uint32_t* ptr) {
#if LLVM_MULTITHREADED==0
++(*ptr);
return *ptr;
#endif
}
-sys::cas_flag sys::AtomicDecrement(volatile sys::cas_flag* ptr) {
+uint32_t sys::AtomicDecrement32(volatile uint32_t* ptr) {
#if LLVM_MULTITHREADED==0
--(*ptr);
return *ptr;
#endif
}
-sys::cas_flag sys::AtomicAdd(volatile sys::cas_flag* ptr, sys::cas_flag val) {
+uint32_t sys::AtomicAdd32(volatile uint32_t* ptr, uint32_t val) {
#if LLVM_MULTITHREADED==0
*ptr += val;
return *ptr;
#endif
}
+uint64_t sys::AtomicAdd64(volatile uint64_t* ptr, uint64_t val) {
+#if LLVM_MULTITHREADED==0
+ *ptr += val;
+ return *ptr;
+#elif defined(__GNUC__)
+ return __sync_add_and_fetch(ptr, val);
+#elif defined(_MSC_VER)
+ return InterlockedAdd64(ptr, val);
+#else
+# error No atomic add implementation for your platform!
+#endif
+}
static uint32_t GlobalID = 0;
unsigned OldID = GlobalID;
- sys::AtomicIncrement(&GlobalID);
+ sys::AtomicIncrement32(&GlobalID);
Name = "__unnamed_" + utostr(TypeUniqueID) + "_" + utostr(OldID);
} else {