diff options
-rw-r--r-- | libcxx/include/__config | 13 | ||||
-rw-r--r-- | libcxx/include/__mutex_base | 20 | ||||
-rw-r--r-- | libcxx/src/CMakeLists.txt | 1 | ||||
-rw-r--r-- | libcxx/src/condition_variable.cpp | 5 | ||||
-rw-r--r-- | libcxx/src/condition_variable_destructor.cpp | 46 |
5 files changed, 66 insertions, 19 deletions
diff --git a/libcxx/include/__config b/libcxx/include/__config index 1ed51699932..1ecced9f479 100644 --- a/libcxx/include/__config +++ b/libcxx/include/__config @@ -1098,13 +1098,22 @@ _LIBCPP_FUNC_VIS extern "C" void __sanitizer_annotate_contiguous_container( #endif // The Apple, glibc, and Bionic implementation of pthreads implements -// pthread_mutex_destroy as nop for regular mutexes. +// pthread_mutex_destroy as nop for regular mutexes. Additionally, Win32 +// mutexes have no destroy mechanism. // TODO(EricWF): Enable this optimization on Apple and Bionic platforms after // speaking to their respective stakeholders. -#if defined(_LIBCPP_HAS_THREAD_API_PTHREAD) && defined(__GLIBC__) +#if (defined(_LIBCPP_HAS_THREAD_API_PTHREAD) && defined(__GLIBC__)) \ + || defined(_LIBCPP_HAS_THREAD_API_WIN32) # define _LIBCPP_HAS_TRIVIAL_MUTEX_DESTRUCTION #endif +// Destroying a condvar is a nop on Windows. +// TODO(EricWF): This is potentially true for some pthread implementations +// as well. +#if defined(_LIBCPP_HAS_THREAD_API_WIN32) +# define _LIBCPP_HAS_TRIVIAL_CONDVAR_DESTRUCTION +#endif + // Systems that use capability-based security (FreeBSD with Capsicum, // Nuxi CloudABI) may only provide local filesystem access (using *at()). // Functions like open(), rename(), unlink() and stat() should not be diff --git a/libcxx/include/__mutex_base b/libcxx/include/__mutex_base index 61abae979ac..f828beaf780 100644 --- a/libcxx/include/__mutex_base +++ b/libcxx/include/__mutex_base @@ -282,26 +282,20 @@ _LIBCPP_DECLARE_STRONG_ENUM_EPILOG(cv_status) class _LIBCPP_TYPE_VIS condition_variable { -#ifndef _LIBCPP_CXX03_LANG __libcpp_condvar_t __cv_ = _LIBCPP_CONDVAR_INITIALIZER; -#else - __libcpp_condvar_t __cv_; -#endif - public: _LIBCPP_INLINE_VISIBILITY -#ifndef _LIBCPP_CXX03_LANG - constexpr condition_variable() _NOEXCEPT = default; + _LIBCPP_CONSTEXPR condition_variable() _NOEXCEPT = default; + +#ifdef _LIBCPP_HAS_TRIVIAL_CONDVAR_DESTRUCTION + ~condition_variable() = default; #else - condition_variable() _NOEXCEPT {__cv_ = (__libcpp_condvar_t)_LIBCPP_CONDVAR_INITIALIZER;} -#endif ~condition_variable(); +#endif -private: - condition_variable(const condition_variable&); // = delete; - condition_variable& operator=(const condition_variable&); // = delete; + condition_variable(const condition_variable&) = delete; + condition_variable& operator=(const condition_variable&) = delete; -public: void notify_one() _NOEXCEPT; void notify_all() _NOEXCEPT; diff --git a/libcxx/src/CMakeLists.txt b/libcxx/src/CMakeLists.txt index 56d7b9888e3..c13f8901581 100644 --- a/libcxx/src/CMakeLists.txt +++ b/libcxx/src/CMakeLists.txt @@ -8,6 +8,7 @@ set(LIBCXX_SOURCES charconv.cpp chrono.cpp condition_variable.cpp + condition_variable_destructor.cpp debug.cpp exception.cpp functional.cpp diff --git a/libcxx/src/condition_variable.cpp b/libcxx/src/condition_variable.cpp index e9b373965e1..b8426c66fde 100644 --- a/libcxx/src/condition_variable.cpp +++ b/libcxx/src/condition_variable.cpp @@ -21,10 +21,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD -condition_variable::~condition_variable() -{ - __libcpp_condvar_destroy(&__cv_); -} +// ~condition_variable is defined elsewhere. void condition_variable::notify_one() _NOEXCEPT diff --git a/libcxx/src/condition_variable_destructor.cpp b/libcxx/src/condition_variable_destructor.cpp new file mode 100644 index 00000000000..44fa240ba78 --- /dev/null +++ b/libcxx/src/condition_variable_destructor.cpp @@ -0,0 +1,46 @@ +//===---------------- condition_variable_destructor.cpp ------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +// Define ~condition_variable. +// +// On some platforms ~condition_variable has been made trivial and the +// definition is only provided for ABI compatibility. + +#include "__config" +#include "__threading_support" + +#if !defined(_LIBCPP_HAS_NO_THREADS) +# if _LIBCPP_ABI_VERSION == 1 || !defined(_LIBCPP_HAS_TRIVIAL_CONDVAR_DESTRUCTION) +# define NEEDS_CONDVAR_DESTRUCTOR +# endif +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +#ifdef NEEDS_CONDVAR_DESTRUCTOR + +class _LIBCPP_TYPE_VIS condition_variable +{ + __libcpp_condvar_t __cv_ = _LIBCPP_CONDVAR_INITIALIZER; +public: + _LIBCPP_INLINE_VISIBILITY + constexpr condition_variable() noexcept = default; + + ~condition_variable(); + + condition_variable(const condition_variable&) = delete; + condition_variable& operator=(const condition_variable&) = delete; +}; + +condition_variable::~condition_variable() +{ + __libcpp_condvar_destroy(&__cv_); +} +#endif + +_LIBCPP_END_NAMESPACE_STD |