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 | 8d0fe6f0d72174bce80ec995352766d26fee6736 (patch) | |
tree | a715fd1a66619e59332ae5c6beb55ce693f71ff7 /llvm/lib/System/Atomic.cpp | |
parent | c39919151d0ee94b2086a063067ff2c42d12fc0b (diff) | |
download | bcm5719-llvm-8d0fe6f0d72174bce80ec995352766d26fee6736.tar.gz bcm5719-llvm-8d0fe6f0d72174bce80ec995352766d26fee6736.zip |
Add an atomic increment and decrement implementation, which will be used for
thread-safe reference counting.
llvm-svn: 73587
Diffstat (limited to 'llvm/lib/System/Atomic.cpp')
-rw-r--r-- | llvm/lib/System/Atomic.cpp | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/llvm/lib/System/Atomic.cpp b/llvm/lib/System/Atomic.cpp index 2827d889659..9d8ac925b89 100644 --- a/llvm/lib/System/Atomic.cpp +++ b/llvm/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 +} + + |