diff options
author | Bruce Mitchener <bruce.mitchener@gmail.com> | 2013-02-17 14:29:14 +0700 |
---|---|---|
committer | Bruce Mitchener <bruce.mitchener@gmail.com> | 2013-03-25 00:34:11 +0700 |
commit | 59ff5a6a3c3e1f5255c5cf29f98df633a77b89b3 (patch) | |
tree | c7660fa62600366e3479dbf6b2fd1d25709af1b5 /system/lib/libcxx/memory.cpp | |
parent | 80fd6f0bce2b95db6ec539c9275ce24585550e7c (diff) |
Update to current libcxx.
This doesn't work yet as it needs to be customized for use with
emscripten still.
Diffstat (limited to 'system/lib/libcxx/memory.cpp')
-rw-r--r-- | system/lib/libcxx/memory.cpp | 55 |
1 files changed, 51 insertions, 4 deletions
diff --git a/system/lib/libcxx/memory.cpp b/system/lib/libcxx/memory.cpp index cb5e5e7b..14084a52 100644 --- a/system/lib/libcxx/memory.cpp +++ b/system/lib/libcxx/memory.cpp @@ -7,7 +7,10 @@ // //===----------------------------------------------------------------------===// +#define _LIBCPP_BUILDING_MEMORY #include "memory" +#include "mutex" +#include "thread" _LIBCPP_BEGIN_NAMESPACE_STD @@ -100,10 +103,7 @@ __shared_weak_count::lock() _NOEXCEPT if (__sync_bool_compare_and_swap(&__shared_owners_, object_owners, object_owners+1)) - { - __add_weak(); return this; - } object_owners = __shared_owners_; } return 0; @@ -119,6 +119,53 @@ __shared_weak_count::__get_deleter(const type_info&) const _NOEXCEPT #endif // _LIBCPP_NO_RTTI +#if __has_feature(cxx_atomic) + +static const std::size_t __sp_mut_count = 16; +static mutex mut_back[__sp_mut_count]; + +_LIBCPP_CONSTEXPR __sp_mut::__sp_mut(void* p) _NOEXCEPT + : __lx(p) +{ +} + +void +__sp_mut::lock() _NOEXCEPT +{ + mutex& m = *static_cast<mutex*>(__lx); + unsigned count = 0; + while (!m.try_lock()) + { + if (++count > 16) + { + m.lock(); + break; + } + this_thread::yield(); + } +} + +void +__sp_mut::unlock() _NOEXCEPT +{ + static_cast<mutex*>(__lx)->unlock(); +} + +__sp_mut& +__get_sp_mut(const void* p) +{ + static __sp_mut muts[__sp_mut_count] + { + &mut_back[ 0], &mut_back[ 1], &mut_back[ 2], &mut_back[ 3], + &mut_back[ 4], &mut_back[ 5], &mut_back[ 6], &mut_back[ 7], + &mut_back[ 8], &mut_back[ 9], &mut_back[10], &mut_back[11], + &mut_back[12], &mut_back[13], &mut_back[14], &mut_back[15] + }; + return muts[hash<const void*>()(p) & (__sp_mut_count-1)]; +} + +#endif // __has_feature(cxx_atomic) + void declare_reachable(void*) { @@ -154,7 +201,7 @@ align(size_t alignment, size_t size, void*& ptr, size_t& space) { char* p1 = static_cast<char*>(ptr); char* p2 = (char*)((size_t)(p1 + (alignment - 1)) & -alignment); - ptrdiff_t d = p2 - p1; + size_t d = static_cast<size_t>(p2 - p1); if (d <= space - size) { r = p2; |