diff options
author | Howard Hinnant <hhinnant@apple.com> | 2010-05-24 17:49:41 +0000 |
---|---|---|
committer | Howard Hinnant <hhinnant@apple.com> | 2010-05-24 17:49:41 +0000 |
commit | 128ba7191da78d948b72b9c7adddc37002b391ef (patch) | |
tree | 777573e0e91f4127e3b389583832de434bff15fc /libcxx/src/memory.cpp | |
parent | 8a57aeca2abfbdd7659af285c10af9e82ba7783d (diff) | |
download | bcm5719-llvm-128ba7191da78d948b72b9c7adddc37002b391ef.tar.gz bcm5719-llvm-128ba7191da78d948b72b9c7adddc37002b391ef.zip |
patch by Jeffrey Yasskin for porting to Ubuntu Hardy. Everything was accepted except there were some bug fixes needed in <locale> for the __nolocale_* series. For the apple branch I ended up using templates instead of the var_args solution because it seemed both safer and more efficient.
llvm-svn: 104516
Diffstat (limited to 'libcxx/src/memory.cpp')
-rw-r--r-- | libcxx/src/memory.cpp | 53 |
1 files changed, 7 insertions, 46 deletions
diff --git a/libcxx/src/memory.cpp b/libcxx/src/memory.cpp index e3075bcb108..f35b838b6bc 100644 --- a/libcxx/src/memory.cpp +++ b/libcxx/src/memory.cpp @@ -8,7 +8,6 @@ //===----------------------------------------------------------------------===// #include "memory" -#include <libkern/OSAtomic.h> _LIBCPP_BEGIN_NAMESPACE_STD @@ -16,57 +15,19 @@ namespace { template <class T> -inline -typename enable_if -< - sizeof(T) * __CHAR_BIT__ == 32, - T ->::type +inline T increment(T& t) { - return OSAtomicIncrement32Barrier((volatile int32_t*)&t); + return __sync_add_and_fetch(&t, 1); } template <class T> -inline -typename enable_if -< - sizeof(T) * __CHAR_BIT__ == 32, - T ->::type +inline T decrement(T& t) { - return OSAtomicDecrement32Barrier((volatile int32_t*)&t); + return __sync_add_and_fetch(&t, -1); } -#ifndef __ppc__ - -template <class T> -inline -typename enable_if -< - sizeof(T) * __CHAR_BIT__ == 64, - T ->::type -increment(T& t) -{ - return OSAtomicIncrement64Barrier((volatile int64_t*)&t); -} - -template <class T> -inline -typename enable_if -< - sizeof(T) * __CHAR_BIT__ == 64, - T ->::type -decrement(T& t) -{ - return OSAtomicDecrement64Barrier((volatile int64_t*)&t); -} - -#endif - } // namespace @@ -134,9 +95,9 @@ __shared_weak_count::lock() long object_owners = __shared_owners_; while (object_owners != -1) { - if (OSAtomicCompareAndSwapLongBarrier(object_owners, - object_owners+1, - &__shared_owners_)) + if (__sync_bool_compare_and_swap(&__shared_owners_, + object_owners, + object_owners+1)) { __add_weak(); return this; |