[libcxx-commits] [libcxx] r365281 - Make ~mutex and ~condition_variable trivial on Windows.
Eric Fiselier via libcxx-commits
libcxx-commits at lists.llvm.org
Sun Jul 7 10:24:04 PDT 2019
Author: ericwf
Date: Sun Jul 7 10:24:03 2019
New Revision: 365281
URL: http://llvm.org/viewvc/llvm-project?rev=365281&view=rev
Log:
Make ~mutex and ~condition_variable trivial on Windows.
The implementations of __libcpp_mutex_destroy and __libcpp_condvar_destroy
are already NOPs, so this optimization is safe to perform.
See r365273 and PR27658 for more information.
Added:
libcxx/trunk/src/condition_variable_destructor.cpp
Modified:
libcxx/trunk/include/__config
libcxx/trunk/include/__mutex_base
libcxx/trunk/src/CMakeLists.txt
libcxx/trunk/src/condition_variable.cpp
Modified: libcxx/trunk/include/__config
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/__config?rev=365281&r1=365280&r2=365281&view=diff
==============================================================================
--- libcxx/trunk/include/__config (original)
+++ libcxx/trunk/include/__config Sun Jul 7 10:24:03 2019
@@ -1098,13 +1098,22 @@ _LIBCPP_FUNC_VIS extern "C" void __sanit
#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
Modified: libcxx/trunk/include/__mutex_base
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/__mutex_base?rev=365281&r1=365280&r2=365281&view=diff
==============================================================================
--- libcxx/trunk/include/__mutex_base (original)
+++ libcxx/trunk/include/__mutex_base Sun Jul 7 10:24:03 2019
@@ -282,26 +282,20 @@ _LIBCPP_DECLARE_STRONG_ENUM_EPILOG(cv_st
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;
Modified: libcxx/trunk/src/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/src/CMakeLists.txt?rev=365281&r1=365280&r2=365281&view=diff
==============================================================================
--- libcxx/trunk/src/CMakeLists.txt (original)
+++ libcxx/trunk/src/CMakeLists.txt Sun Jul 7 10:24:03 2019
@@ -8,6 +8,7 @@ set(LIBCXX_SOURCES
charconv.cpp
chrono.cpp
condition_variable.cpp
+ condition_variable_destructor.cpp
debug.cpp
exception.cpp
functional.cpp
Modified: libcxx/trunk/src/condition_variable.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/src/condition_variable.cpp?rev=365281&r1=365280&r2=365281&view=diff
==============================================================================
--- libcxx/trunk/src/condition_variable.cpp (original)
+++ libcxx/trunk/src/condition_variable.cpp Sun Jul 7 10:24:03 2019
@@ -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
Added: libcxx/trunk/src/condition_variable_destructor.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/src/condition_variable_destructor.cpp?rev=365281&view=auto
==============================================================================
--- libcxx/trunk/src/condition_variable_destructor.cpp (added)
+++ libcxx/trunk/src/condition_variable_destructor.cpp Sun Jul 7 10:24:03 2019
@@ -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
More information about the libcxx-commits
mailing list