diff options
| author | Owen Anderson <resistor@mac.com> | 2009-06-17 00:13:00 +0000 |
|---|---|---|
| committer | Owen Anderson <resistor@mac.com> | 2009-06-17 00:13:00 +0000 |
| commit | 465fa539bf341199988315c02f16a0cbe9425c21 (patch) | |
| tree | 3da7419e06a5b3fe7e8293549c75907e8b1257f1 | |
| parent | 060efe5364315874e17517cb01e0b553501af0da (diff) | |
| download | external_llvm-465fa539bf341199988315c02f16a0cbe9425c21.zip external_llvm-465fa539bf341199988315c02f16a0cbe9425c21.tar.gz external_llvm-465fa539bf341199988315c02f16a0cbe9425c21.tar.bz2 | |
Add an atomic increment and decrement implementation, which will be used for
thread-safe reference counting.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@73587 91177308-0d34-0410-b5e6-96231b3b80d8
| -rw-r--r-- | autoconf/configure.ac | 2 | ||||
| -rwxr-xr-x | configure | 2 | ||||
| -rw-r--r-- | include/llvm/System/Atomic.h | 2 | ||||
| -rw-r--r-- | include/llvm/Type.h | 5 | ||||
| -rw-r--r-- | lib/System/Atomic.cpp | 28 |
5 files changed, 35 insertions, 4 deletions
diff --git a/autoconf/configure.ac b/autoconf/configure.ac index 828e558..4ba6b2b 100644 --- a/autoconf/configure.ac +++ b/autoconf/configure.ac @@ -935,6 +935,8 @@ AC_LINK_IFELSE( volatile unsigned long val = 1; __sync_synchronize(); __sync_val_compare_and_swap(&val, 1, 0); + __sync_add_and_fetch(&val, 1); + __sync_sub_and_fetch(&val, 1); return 0; } ]]), @@ -33760,6 +33760,8 @@ int main() { volatile unsigned long val = 1; __sync_synchronize(); __sync_val_compare_and_swap(&val, 1, 0); + __sync_add_and_fetch(&val, 1); + __sync_sub_and_fetch(&val, 1); return 0; } diff --git a/include/llvm/System/Atomic.h b/include/llvm/System/Atomic.h index cb9277c..f90a8f6 100644 --- a/include/llvm/System/Atomic.h +++ b/include/llvm/System/Atomic.h @@ -24,6 +24,8 @@ namespace llvm { cas_flag CompareAndSwap(volatile cas_flag* ptr, cas_flag new_value, cas_flag old_value); + cas_flag AtomicPostIncrement(volatile cas_flag* ptr); + cas_flag AtomicPostDecrement(volatile cas_flag* ptr); } } diff --git a/include/llvm/Type.h b/include/llvm/Type.h index 9a48731..256944f 100644 --- a/include/llvm/Type.h +++ b/include/llvm/Type.h @@ -353,10 +353,7 @@ public: /// addAbstractTypeUser - Notify an abstract type that there is a new user of /// it. This function is called primarily by the PATypeHandle class. /// - void addAbstractTypeUser(AbstractTypeUser *U) const { - assert(isAbstract() && "addAbstractTypeUser: Current type not abstract!"); - AbstractTypeUsers.push_back(U); - } + void addAbstractTypeUser(AbstractTypeUser *U) const; /// removeAbstractTypeUser - Notify an abstract type that a user of the class /// no longer has a handle to the type. This function is called primarily by diff --git a/lib/System/Atomic.cpp b/lib/System/Atomic.cpp index 2827d88..9d8ac92 100644 --- a/lib/System/Atomic.cpp +++ b/lib/System/Atomic.cpp @@ -51,3 +51,31 @@ sys::cas_flag sys::CompareAndSwap(volatile sys::cas_flag* ptr, # error No compare-and-swap implementation for your platform! #endif } + +sys::cas_flag sys::AtomicPostIncrement(volatile sys::cas_flag* ptr) { +#if LLVM_MULTITHREADED==0 + ++(*ptr); + return *ptr; +#elif defined(__GNUC__) + return __sync_add_and_fetch(ptr, 1); +#elif defined(_MSC_VER) + return InterlockedCompareExchange(ptr, new_value, old_value); +#else +# error No atomic increment implementation for your platform! +#endif +} + +sys::cas_flag sys::AtomicPostDecrement(volatile sys::cas_flag* ptr) { +#if LLVM_MULTITHREADED==0 + --(*ptr); + return *ptr; +#elif defined(__GNUC__) + return __sync_sub_and_fetch(ptr, 1); +#elif defined(_MSC_VER) + return InterlockedIncrement(ptr); +#else +# error No atomic decrement implementation for your platform! +#endif +} + + |
