[Test patch] Inline hot functions in libcxx shared_ptr

Moves hot functions such as atomic add into the memory header file
so that they can be inlined, which brings performance benefits.

Patch by Kevin Hu, Aditya Kumar, Sebastian Pop

Differential Revision: https://reviews.llvm.org/D24991


git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@292184 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Kevin Hu
2017-01-17 02:46:33 +00:00
parent 2e5a364ebc
commit 8993759ae9
2 changed files with 77 additions and 35 deletions

View File

@@ -17,28 +17,6 @@
_LIBCPP_BEGIN_NAMESPACE_STD
namespace
{
// NOTE: Relaxed and acq/rel atomics (for increment and decrement respectively)
// should be sufficient for thread safety.
// See https://llvm.org/bugs/show_bug.cgi?id=22803
template <class T>
inline T
increment(T& t) _NOEXCEPT
{
return __libcpp_atomic_add(&t, 1, _AO_Relaxed);
}
template <class T>
inline T
decrement(T& t) _NOEXCEPT
{
return __libcpp_atomic_add(&t, -1, _AO_Acq_Rel);
}
} // namespace
const allocator_arg_t allocator_arg = allocator_arg_t();
bad_weak_ptr::~bad_weak_ptr() _NOEXCEPT {}
@@ -53,16 +31,20 @@ __shared_count::~__shared_count()
{
}
__shared_weak_count::~__shared_weak_count()
{
}
void
__shared_count::__add_shared() _NOEXCEPT
{
increment(__shared_owners_);
__libcpp_atomic_refcount_increment(__shared_owners_);
}
bool
__shared_count::__release_shared() _NOEXCEPT
{
if (decrement(__shared_owners_) == -1)
if (__libcpp_atomic_refcount_decrement(__shared_owners_) == -1)
{
__on_zero_shared();
return true;
@@ -70,10 +52,6 @@ __shared_count::__release_shared() _NOEXCEPT
return false;
}
__shared_weak_count::~__shared_weak_count()
{
}
void
__shared_weak_count::__add_shared() _NOEXCEPT
{
@@ -83,7 +61,7 @@ __shared_weak_count::__add_shared() _NOEXCEPT
void
__shared_weak_count::__add_weak() _NOEXCEPT
{
increment(__shared_weak_owners_);
__libcpp_atomic_refcount_increment(__shared_weak_owners_);
}
void
@@ -124,7 +102,7 @@ __shared_weak_count::__release_weak() _NOEXCEPT
//__libcpp_atomic_store(&__shared_weak_owners_, -1, _AO_Release);
__on_zero_shared_weak();
}
else if (decrement(__shared_weak_owners_) == -1)
else if (__libcpp_atomic_refcount_decrement(__shared_weak_owners_) == -1)
__on_zero_shared_weak();
}