summaryrefslogtreecommitdiffstats
path: root/contrib/libc++/src/memory.cpp
diff options
context:
space:
mode:
authordim <dim@FreeBSD.org>2012-10-22 18:25:04 +0000
committerdim <dim@FreeBSD.org>2012-10-22 18:25:04 +0000
commit708d8e446e991358da23bb52ec5320440221f12f (patch)
tree3a061d75674cd5b60d9f6df45d0b8d755da3782f /contrib/libc++/src/memory.cpp
parentb8c74d455d2690e710a0802a98a9d310995a52eb (diff)
parent13334223d751d249ccd6475b8cba36ff71ddc972 (diff)
downloadFreeBSD-src-708d8e446e991358da23bb52ec5320440221f12f.zip
FreeBSD-src-708d8e446e991358da23bb52ec5320440221f12f.tar.gz
Import libc++ trunk r165949. Among other improvements and bug fixes,
this has many visibility problems fixed, which should help with compiling certain ports that exercise C++11 mode (i.e. Firefox). Also, belatedly add the LICENSE.TXT and accompanying CREDITS.TXT files, which are referred to in all the source files. MFC after: 1 month
Diffstat (limited to 'contrib/libc++/src/memory.cpp')
-rw-r--r--contrib/libc++/src/memory.cpp50
1 files changed, 50 insertions, 0 deletions
diff --git a/contrib/libc++/src/memory.cpp b/contrib/libc++/src/memory.cpp
index a892e75..3884a2b 100644
--- a/contrib/libc++/src/memory.cpp
+++ b/contrib/libc++/src/memory.cpp
@@ -7,7 +7,10 @@
//
//===----------------------------------------------------------------------===//
+#define _LIBCPP_BUILDING_MEMORY
#include "memory"
+#include "mutex"
+#include "thread"
_LIBCPP_BEGIN_NAMESPACE_STD
@@ -116,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
+ : _(p)
+{
+}
+
+void
+__sp_mut::lock() _NOEXCEPT
+{
+ mutex& m = *static_cast<mutex*>(_);
+ unsigned count = 0;
+ while (!m.try_lock())
+ {
+ if (++count > 16)
+ {
+ m.lock();
+ break;
+ }
+ this_thread::yield();
+ }
+}
+
+void
+__sp_mut::unlock() _NOEXCEPT
+{
+ static_cast<mutex*>(_)->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*)
{
OpenPOWER on IntegriCloud