forked from OSchip/llvm-project
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. llvm-svn: 365281
This commit is contained in:
parent
8721001558
commit
8cedf04a6c
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@ set(LIBCXX_SOURCES
|
|||
charconv.cpp
|
||||
chrono.cpp
|
||||
condition_variable.cpp
|
||||
condition_variable_destructor.cpp
|
||||
debug.cpp
|
||||
exception.cpp
|
||||
functional.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
|
||||
|
|
|
@ -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
|
Loading…
Reference in New Issue