Mark libc++ internal globals with _LIBCPP_SAFE_STATIC.
This patch applies the _LIBCPP_SAFE_STATIC attribute to internal globals, most of which are locking primitives, in order to ensure that they can safely be used during program startup. This patch also fixes an unsafe static init issue with the global locks used to implement atomic operations on shared pointers. Previously the locks were initialized using a dynamically initialized pointer, so it was possible that the pointer was uninitialized. git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@282640 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -48,7 +48,7 @@ template bool __insertion_sort_incomplete<__less<long double>&, long double*>(lo
|
|||||||
template unsigned __sort5<__less<long double>&, long double*>(long double*, long double*, long double*, long double*, long double*, __less<long double>&);
|
template unsigned __sort5<__less<long double>&, long double*>(long double*, long double*, long double*, long double*, long double*, __less<long double>&);
|
||||||
|
|
||||||
#ifndef _LIBCPP_HAS_NO_THREADS
|
#ifndef _LIBCPP_HAS_NO_THREADS
|
||||||
static __libcpp_mutex_t __rs_mut = _LIBCPP_MUTEX_INITIALIZER;
|
_LIBCPP_SAFE_STATIC static __libcpp_mutex_t __rs_mut = _LIBCPP_MUTEX_INITIALIZER;
|
||||||
#endif
|
#endif
|
||||||
unsigned __rs_default::__c_ = 0;
|
unsigned __rs_default::__c_ = 0;
|
||||||
|
|
||||||
|
|||||||
@@ -32,8 +32,8 @@
|
|||||||
#define HAVE_DEPENDENT_EH_ABI 1
|
#define HAVE_DEPENDENT_EH_ABI 1
|
||||||
#endif
|
#endif
|
||||||
#elif !defined(__GLIBCXX__) // defined(LIBCXX_BUILDING_LIBCXXABI)
|
#elif !defined(__GLIBCXX__) // defined(LIBCXX_BUILDING_LIBCXXABI)
|
||||||
static std::terminate_handler __terminate_handler;
|
_LIBCPP_SAFE_STATIC static std::terminate_handler __terminate_handler;
|
||||||
static std::unexpected_handler __unexpected_handler;
|
_LIBCPP_SAFE_STATIC static std::unexpected_handler __unexpected_handler;
|
||||||
#endif // defined(LIBCXX_BUILDING_LIBCXXABI)
|
#endif // defined(LIBCXX_BUILDING_LIBCXXABI)
|
||||||
|
|
||||||
namespace std
|
namespace std
|
||||||
|
|||||||
@@ -154,8 +154,8 @@ __shared_weak_count::__get_deleter(const type_info&) const _NOEXCEPT
|
|||||||
|
|
||||||
#if !defined(_LIBCPP_HAS_NO_ATOMIC_HEADER)
|
#if !defined(_LIBCPP_HAS_NO_ATOMIC_HEADER)
|
||||||
|
|
||||||
static const std::size_t __sp_mut_count = 16;
|
_LIBCPP_SAFE_STATIC static const std::size_t __sp_mut_count = 16;
|
||||||
static __libcpp_mutex_t mut_back_imp[__sp_mut_count] =
|
_LIBCPP_SAFE_STATIC static __libcpp_mutex_t mut_back[__sp_mut_count] =
|
||||||
{
|
{
|
||||||
_LIBCPP_MUTEX_INITIALIZER, _LIBCPP_MUTEX_INITIALIZER, _LIBCPP_MUTEX_INITIALIZER, _LIBCPP_MUTEX_INITIALIZER,
|
_LIBCPP_MUTEX_INITIALIZER, _LIBCPP_MUTEX_INITIALIZER, _LIBCPP_MUTEX_INITIALIZER, _LIBCPP_MUTEX_INITIALIZER,
|
||||||
_LIBCPP_MUTEX_INITIALIZER, _LIBCPP_MUTEX_INITIALIZER, _LIBCPP_MUTEX_INITIALIZER, _LIBCPP_MUTEX_INITIALIZER,
|
_LIBCPP_MUTEX_INITIALIZER, _LIBCPP_MUTEX_INITIALIZER, _LIBCPP_MUTEX_INITIALIZER, _LIBCPP_MUTEX_INITIALIZER,
|
||||||
@@ -163,8 +163,6 @@ static __libcpp_mutex_t mut_back_imp[__sp_mut_count] =
|
|||||||
_LIBCPP_MUTEX_INITIALIZER, _LIBCPP_MUTEX_INITIALIZER, _LIBCPP_MUTEX_INITIALIZER, _LIBCPP_MUTEX_INITIALIZER
|
_LIBCPP_MUTEX_INITIALIZER, _LIBCPP_MUTEX_INITIALIZER, _LIBCPP_MUTEX_INITIALIZER, _LIBCPP_MUTEX_INITIALIZER
|
||||||
};
|
};
|
||||||
|
|
||||||
static mutex* mut_back = reinterpret_cast<std::mutex*>(mut_back_imp);
|
|
||||||
|
|
||||||
_LIBCPP_CONSTEXPR __sp_mut::__sp_mut(void* p) _NOEXCEPT
|
_LIBCPP_CONSTEXPR __sp_mut::__sp_mut(void* p) _NOEXCEPT
|
||||||
: __lx(p)
|
: __lx(p)
|
||||||
{
|
{
|
||||||
@@ -173,13 +171,13 @@ _LIBCPP_CONSTEXPR __sp_mut::__sp_mut(void* p) _NOEXCEPT
|
|||||||
void
|
void
|
||||||
__sp_mut::lock() _NOEXCEPT
|
__sp_mut::lock() _NOEXCEPT
|
||||||
{
|
{
|
||||||
mutex& m = *static_cast<mutex*>(__lx);
|
auto m = static_cast<__libcpp_mutex_t*>(__lx);
|
||||||
unsigned count = 0;
|
unsigned count = 0;
|
||||||
while (!m.try_lock())
|
while (__libcpp_mutex_trylock(m) != 0)
|
||||||
{
|
{
|
||||||
if (++count > 16)
|
if (++count > 16)
|
||||||
{
|
{
|
||||||
m.lock();
|
__libcpp_mutex_lock(m);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
this_thread::yield();
|
this_thread::yield();
|
||||||
@@ -189,7 +187,7 @@ __sp_mut::lock() _NOEXCEPT
|
|||||||
void
|
void
|
||||||
__sp_mut::unlock() _NOEXCEPT
|
__sp_mut::unlock() _NOEXCEPT
|
||||||
{
|
{
|
||||||
static_cast<mutex*>(__lx)->unlock();
|
__libcpp_mutex_unlock(static_cast<__libcpp_mutex_t*>(__lx));
|
||||||
}
|
}
|
||||||
|
|
||||||
__sp_mut&
|
__sp_mut&
|
||||||
|
|||||||
@@ -195,8 +195,8 @@ recursive_timed_mutex::unlock() _NOEXCEPT
|
|||||||
// keep in sync with: 7741191.
|
// keep in sync with: 7741191.
|
||||||
|
|
||||||
#ifndef _LIBCPP_HAS_NO_THREADS
|
#ifndef _LIBCPP_HAS_NO_THREADS
|
||||||
static __libcpp_mutex_t mut = _LIBCPP_MUTEX_INITIALIZER;
|
_LIBCPP_SAFE_STATIC static __libcpp_mutex_t mut = _LIBCPP_MUTEX_INITIALIZER;
|
||||||
static __libcpp_condvar_t cv = _LIBCPP_CONDVAR_INITIALIZER;
|
_LIBCPP_SAFE_STATIC static __libcpp_condvar_t cv = _LIBCPP_CONDVAR_INITIALIZER;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|||||||
Reference in New Issue
Block a user